blob: 7fa3ae36383573f33e683d59324b855cae3c459a [file] [log] [blame]
sprang@webrtc.orgccd42842014-01-07 09:54:341/*
2 * Copyright (c) 2013 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
sprang@webrtc.orgccd42842014-01-07 09:54:3411#include "webrtc/video/send_statistics_proxy.h"
12
13#include <map>
kwiberg27f982b2016-03-01 19:52:3314#include <memory>
sprang@webrtc.orgccd42842014-01-07 09:54:3415#include <string>
16#include <vector>
17
sprang07fb9be2016-02-24 15:55:0018#include "webrtc/system_wrappers/include/metrics.h"
asapersson01d70a32016-05-20 13:29:4619#include "webrtc/system_wrappers/include/metrics_default.h"
kwibergac9f8762016-10-01 05:29:4320#include "webrtc/test/gtest.h"
sprang@webrtc.orgccd42842014-01-07 09:54:3421
22namespace webrtc {
asapersson5265fed2016-04-18 09:58:4723namespace {
24const uint32_t kFirstSsrc = 17;
25const uint32_t kSecondSsrc = 42;
26const uint32_t kFirstRtxSsrc = 18;
27const uint32_t kSecondRtxSsrc = 43;
asaperssona6a699a2016-11-25 11:52:4628const uint32_t kFlexFecSsrc = 55;
asapersson320e45a2016-11-29 09:40:3529const int kFpsPeriodicIntervalMs = 2000;
30const int kWidth = 640;
31const int kHeight = 480;
asapersson5265fed2016-04-18 09:58:4732const int kQpIdx0 = 21;
33const int kQpIdx1 = 39;
kthelgason0cd27ba2016-12-19 14:32:1634const CodecSpecificInfo kDefaultCodecInfo = []() {
35 CodecSpecificInfo codec_info;
36 codec_info.codecType = kVideoCodecVP8;
37 codec_info.codecSpecific.VP8.simulcastIdx = 0;
38 return codec_info;
39}();
asapersson5265fed2016-04-18 09:58:4740} // namespace
sprang07fb9be2016-02-24 15:55:0041
stefan@webrtc.org168f23f2014-07-11 13:44:0242class SendStatisticsProxyTest : public ::testing::Test {
sprang@webrtc.orgccd42842014-01-07 09:54:3443 public:
pbos@webrtc.org273a4142014-12-01 15:23:2144 SendStatisticsProxyTest()
solenberg4fbae2b2015-08-28 11:07:1045 : fake_clock_(1234), config_(GetTestConfig()), avg_delay_ms_(0),
46 max_delay_ms_(0) {}
sprang@webrtc.orgccd42842014-01-07 09:54:3447 virtual ~SendStatisticsProxyTest() {}
48
49 protected:
50 virtual void SetUp() {
asapersson01d70a32016-05-20 13:29:4651 metrics::Reset();
sprangb4a1ae52015-12-03 16:10:0852 statistics_proxy_.reset(new SendStatisticsProxy(
53 &fake_clock_, GetTestConfig(),
54 VideoEncoderConfig::ContentType::kRealtimeVideo));
sprang@webrtc.orgccd42842014-01-07 09:54:3455 expected_ = VideoSendStream::Stats();
asapersson2e5cfcd2016-08-11 15:41:1856 for (const auto& ssrc : config_.rtp.ssrcs)
57 expected_.substreams[ssrc].is_rtx = false;
58 for (const auto& ssrc : config_.rtp.rtx.ssrcs)
59 expected_.substreams[ssrc].is_rtx = true;
sprang@webrtc.orgccd42842014-01-07 09:54:3460 }
61
62 VideoSendStream::Config GetTestConfig() {
solenberg4fbae2b2015-08-28 11:07:1063 VideoSendStream::Config config(nullptr);
sprang07fb9be2016-02-24 15:55:0064 config.rtp.ssrcs.push_back(kFirstSsrc);
65 config.rtp.ssrcs.push_back(kSecondSsrc);
66 config.rtp.rtx.ssrcs.push_back(kFirstRtxSsrc);
67 config.rtp.rtx.ssrcs.push_back(kSecondRtxSsrc);
brandtrb5f2c3f2016-10-05 06:28:3968 config.rtp.ulpfec.red_payload_type = 17;
sprang@webrtc.orgccd42842014-01-07 09:54:3469 return config;
70 }
71
asaperssona6a699a2016-11-25 11:52:4672 VideoSendStream::Config GetTestConfigWithFlexFec() {
73 VideoSendStream::Config config(nullptr);
74 config.rtp.ssrcs.push_back(kFirstSsrc);
75 config.rtp.ssrcs.push_back(kSecondSsrc);
76 config.rtp.rtx.ssrcs.push_back(kFirstRtxSsrc);
77 config.rtp.rtx.ssrcs.push_back(kSecondRtxSsrc);
78 config.rtp.flexfec.flexfec_payload_type = 50;
79 config.rtp.flexfec.flexfec_ssrc = kFlexFecSsrc;
80 return config;
81 }
82
83 VideoSendStream::StreamStats GetStreamStats(uint32_t ssrc) {
84 VideoSendStream::Stats stats = statistics_proxy_->GetStats();
85 std::map<uint32_t, VideoSendStream::StreamStats>::iterator it =
86 stats.substreams.find(ssrc);
87 EXPECT_NE(it, stats.substreams.end());
88 return it->second;
89 }
90
asapersson66d4b372016-12-19 14:50:5391 void UpdateDataCounters(uint32_t ssrc) {
92 StreamDataCountersCallback* proxy =
93 static_cast<StreamDataCountersCallback*>(statistics_proxy_.get());
94 StreamDataCounters counters;
95 proxy->DataCountersUpdated(counters, ssrc);
96 }
97
sprang@webrtc.org09315702014-02-07 12:06:2998 void ExpectEqual(VideoSendStream::Stats one, VideoSendStream::Stats other) {
sprang@webrtc.org09315702014-02-07 12:06:2999 EXPECT_EQ(one.input_frame_rate, other.input_frame_rate);
100 EXPECT_EQ(one.encode_frame_rate, other.encode_frame_rate);
stefan@webrtc.org0bae1fa2014-11-05 14:05:29101 EXPECT_EQ(one.media_bitrate_bps, other.media_bitrate_bps);
Pera48ddb72016-09-29 09:48:50102 EXPECT_EQ(one.preferred_media_bitrate_bps,
103 other.preferred_media_bitrate_bps);
henrik.lundin@webrtc.orgb10363f32014-03-13 13:31:21104 EXPECT_EQ(one.suspended, other.suspended);
sprang@webrtc.org09315702014-02-07 12:06:29105
106 EXPECT_EQ(one.substreams.size(), other.substreams.size());
pbos@webrtc.org09c77b92015-02-25 10:42:16107 for (std::map<uint32_t, VideoSendStream::StreamStats>::const_iterator it =
sprang@webrtc.org09315702014-02-07 12:06:29108 one.substreams.begin();
pbos@webrtc.org09c77b92015-02-25 10:42:16109 it != one.substreams.end(); ++it) {
110 std::map<uint32_t, VideoSendStream::StreamStats>::const_iterator
111 corresponding_it = other.substreams.find(it->first);
sprang@webrtc.org09315702014-02-07 12:06:29112 ASSERT_TRUE(corresponding_it != other.substreams.end());
pbos@webrtc.org09c77b92015-02-25 10:42:16113 const VideoSendStream::StreamStats& a = it->second;
114 const VideoSendStream::StreamStats& b = corresponding_it->second;
sprang@webrtc.org09315702014-02-07 12:06:29115
asapersson2e5cfcd2016-08-11 15:41:18116 EXPECT_EQ(a.is_rtx, b.is_rtx);
pbos@webrtc.orgce4e9a32014-12-18 13:50:16117 EXPECT_EQ(a.frame_counts.key_frames, b.frame_counts.key_frames);
118 EXPECT_EQ(a.frame_counts.delta_frames, b.frame_counts.delta_frames);
stefan@webrtc.org0bae1fa2014-11-05 14:05:29119 EXPECT_EQ(a.total_bitrate_bps, b.total_bitrate_bps);
stefan@webrtc.org168f23f2014-07-11 13:44:02120 EXPECT_EQ(a.avg_delay_ms, b.avg_delay_ms);
121 EXPECT_EQ(a.max_delay_ms, b.max_delay_ms);
sprang@webrtc.org09315702014-02-07 12:06:29122
asapersson@webrtc.orgcfd82df2015-01-22 09:39:59123 EXPECT_EQ(a.rtp_stats.transmitted.payload_bytes,
124 b.rtp_stats.transmitted.payload_bytes);
125 EXPECT_EQ(a.rtp_stats.transmitted.header_bytes,
126 b.rtp_stats.transmitted.header_bytes);
127 EXPECT_EQ(a.rtp_stats.transmitted.padding_bytes,
128 b.rtp_stats.transmitted.padding_bytes);
129 EXPECT_EQ(a.rtp_stats.transmitted.packets,
130 b.rtp_stats.transmitted.packets);
131 EXPECT_EQ(a.rtp_stats.retransmitted.packets,
132 b.rtp_stats.retransmitted.packets);
133 EXPECT_EQ(a.rtp_stats.fec.packets, b.rtp_stats.fec.packets);
sprang@webrtc.org09315702014-02-07 12:06:29134
135 EXPECT_EQ(a.rtcp_stats.fraction_lost, b.rtcp_stats.fraction_lost);
136 EXPECT_EQ(a.rtcp_stats.cumulative_lost, b.rtcp_stats.cumulative_lost);
137 EXPECT_EQ(a.rtcp_stats.extended_max_sequence_number,
138 b.rtcp_stats.extended_max_sequence_number);
139 EXPECT_EQ(a.rtcp_stats.jitter, b.rtcp_stats.jitter);
140 }
141 }
142
pbos@webrtc.org273a4142014-12-01 15:23:21143 SimulatedClock fake_clock_;
kwiberg27f982b2016-03-01 19:52:33144 std::unique_ptr<SendStatisticsProxy> statistics_proxy_;
sprang@webrtc.orgccd42842014-01-07 09:54:34145 VideoSendStream::Config config_;
146 int avg_delay_ms_;
147 int max_delay_ms_;
sprang@webrtc.orgccd42842014-01-07 09:54:34148 VideoSendStream::Stats expected_;
pbos@webrtc.org09c77b92015-02-25 10:42:16149 typedef std::map<uint32_t, VideoSendStream::StreamStats>::const_iterator
150 StreamIterator;
sprang@webrtc.orgccd42842014-01-07 09:54:34151};
152
153TEST_F(SendStatisticsProxyTest, RtcpStatistics) {
154 RtcpStatisticsCallback* callback = statistics_proxy_.get();
asapersson35151f32016-05-03 06:44:01155 for (const auto& ssrc : config_.rtp.ssrcs) {
pbos@webrtc.org09c77b92015-02-25 10:42:16156 VideoSendStream::StreamStats& ssrc_stats = expected_.substreams[ssrc];
sprang@webrtc.orgccd42842014-01-07 09:54:34157
158 // Add statistics with some arbitrary, but unique, numbers.
159 uint32_t offset = ssrc * sizeof(RtcpStatistics);
160 ssrc_stats.rtcp_stats.cumulative_lost = offset;
161 ssrc_stats.rtcp_stats.extended_max_sequence_number = offset + 1;
162 ssrc_stats.rtcp_stats.fraction_lost = offset + 2;
163 ssrc_stats.rtcp_stats.jitter = offset + 3;
164 callback->StatisticsUpdated(ssrc_stats.rtcp_stats, ssrc);
165 }
asapersson35151f32016-05-03 06:44:01166 for (const auto& ssrc : config_.rtp.rtx.ssrcs) {
pbos@webrtc.org09c77b92015-02-25 10:42:16167 VideoSendStream::StreamStats& ssrc_stats = expected_.substreams[ssrc];
sprang@webrtc.orgccd42842014-01-07 09:54:34168
stefan@webrtc.org58e2d262014-08-14 15:10:49169 // Add statistics with some arbitrary, but unique, numbers.
170 uint32_t offset = ssrc * sizeof(RtcpStatistics);
171 ssrc_stats.rtcp_stats.cumulative_lost = offset;
172 ssrc_stats.rtcp_stats.extended_max_sequence_number = offset + 1;
173 ssrc_stats.rtcp_stats.fraction_lost = offset + 2;
174 ssrc_stats.rtcp_stats.jitter = offset + 3;
175 callback->StatisticsUpdated(ssrc_stats.rtcp_stats, ssrc);
176 }
sprang@webrtc.orgccd42842014-01-07 09:54:34177 VideoSendStream::Stats stats = statistics_proxy_->GetStats();
sprang@webrtc.org09315702014-02-07 12:06:29178 ExpectEqual(expected_, stats);
sprang@webrtc.orgccd42842014-01-07 09:54:34179}
180
stefan@webrtc.org0bae1fa2014-11-05 14:05:29181TEST_F(SendStatisticsProxyTest, EncodedBitrateAndFramerate) {
Peter Boström7083e112015-09-22 14:28:51182 int media_bitrate_bps = 500;
183 int encode_fps = 29;
stefan@webrtc.org0bae1fa2014-11-05 14:05:29184
perkj275afc52016-09-01 07:21:16185 statistics_proxy_->OnEncoderStatsUpdate(encode_fps, media_bitrate_bps);
stefan@webrtc.org0bae1fa2014-11-05 14:05:29186
187 VideoSendStream::Stats stats = statistics_proxy_->GetStats();
188 EXPECT_EQ(media_bitrate_bps, stats.media_bitrate_bps);
sprang@webrtc.orgccd42842014-01-07 09:54:34189 EXPECT_EQ(encode_fps, stats.encode_frame_rate);
190}
191
henrik.lundin@webrtc.orgb10363f32014-03-13 13:31:21192TEST_F(SendStatisticsProxyTest, Suspended) {
193 // Verify that the value is false by default.
194 EXPECT_FALSE(statistics_proxy_->GetStats().suspended);
195
196 // Verify that we can set it to true.
Peter Boström7083e112015-09-22 14:28:51197 statistics_proxy_->OnSuspendChange(true);
henrik.lundin@webrtc.orgb10363f32014-03-13 13:31:21198 EXPECT_TRUE(statistics_proxy_->GetStats().suspended);
199
200 // Verify that we can set it back to false again.
Peter Boström7083e112015-09-22 14:28:51201 statistics_proxy_->OnSuspendChange(false);
henrik.lundin@webrtc.orgb10363f32014-03-13 13:31:21202 EXPECT_FALSE(statistics_proxy_->GetStats().suspended);
203}
204
sprang@webrtc.orgccd42842014-01-07 09:54:34205TEST_F(SendStatisticsProxyTest, FrameCounts) {
206 FrameCountObserver* observer = statistics_proxy_.get();
asapersson35151f32016-05-03 06:44:01207 for (const auto& ssrc : config_.rtp.ssrcs) {
sprang@webrtc.orgccd42842014-01-07 09:54:34208 // Add statistics with some arbitrary, but unique, numbers.
pbos@webrtc.org09c77b92015-02-25 10:42:16209 VideoSendStream::StreamStats& stats = expected_.substreams[ssrc];
210 uint32_t offset = ssrc * sizeof(VideoSendStream::StreamStats);
pbos@webrtc.orgce4e9a32014-12-18 13:50:16211 FrameCounts frame_counts;
212 frame_counts.key_frames = offset;
213 frame_counts.delta_frames = offset + 1;
214 stats.frame_counts = frame_counts;
215 observer->FrameCountUpdated(frame_counts, ssrc);
sprang@webrtc.orgccd42842014-01-07 09:54:34216 }
asapersson35151f32016-05-03 06:44:01217 for (const auto& ssrc : config_.rtp.rtx.ssrcs) {
stefan@webrtc.org58e2d262014-08-14 15:10:49218 // Add statistics with some arbitrary, but unique, numbers.
pbos@webrtc.org09c77b92015-02-25 10:42:16219 VideoSendStream::StreamStats& stats = expected_.substreams[ssrc];
220 uint32_t offset = ssrc * sizeof(VideoSendStream::StreamStats);
pbos@webrtc.orgce4e9a32014-12-18 13:50:16221 FrameCounts frame_counts;
222 frame_counts.key_frames = offset;
223 frame_counts.delta_frames = offset + 1;
224 stats.frame_counts = frame_counts;
225 observer->FrameCountUpdated(frame_counts, ssrc);
stefan@webrtc.org58e2d262014-08-14 15:10:49226 }
sprang@webrtc.orgccd42842014-01-07 09:54:34227
228 VideoSendStream::Stats stats = statistics_proxy_->GetStats();
sprang@webrtc.org09315702014-02-07 12:06:29229 ExpectEqual(expected_, stats);
sprang@webrtc.orgccd42842014-01-07 09:54:34230}
231
232TEST_F(SendStatisticsProxyTest, DataCounters) {
233 StreamDataCountersCallback* callback = statistics_proxy_.get();
asapersson35151f32016-05-03 06:44:01234 for (const auto& ssrc : config_.rtp.ssrcs) {
sprang@webrtc.orgccd42842014-01-07 09:54:34235 StreamDataCounters& counters = expected_.substreams[ssrc].rtp_stats;
236 // Add statistics with some arbitrary, but unique, numbers.
pkasting@chromium.org4591fbd2014-11-20 22:28:14237 size_t offset = ssrc * sizeof(StreamDataCounters);
238 uint32_t offset_uint32 = static_cast<uint32_t>(offset);
asapersson@webrtc.orgcfd82df2015-01-22 09:39:59239 counters.transmitted.payload_bytes = offset;
240 counters.transmitted.header_bytes = offset + 1;
241 counters.fec.packets = offset_uint32 + 2;
242 counters.transmitted.padding_bytes = offset + 3;
243 counters.retransmitted.packets = offset_uint32 + 4;
244 counters.transmitted.packets = offset_uint32 + 5;
sprang@webrtc.orgccd42842014-01-07 09:54:34245 callback->DataCountersUpdated(counters, ssrc);
246 }
asapersson35151f32016-05-03 06:44:01247 for (const auto& ssrc : config_.rtp.rtx.ssrcs) {
stefan@webrtc.org58e2d262014-08-14 15:10:49248 StreamDataCounters& counters = expected_.substreams[ssrc].rtp_stats;
249 // Add statistics with some arbitrary, but unique, numbers.
pkasting@chromium.org4591fbd2014-11-20 22:28:14250 size_t offset = ssrc * sizeof(StreamDataCounters);
251 uint32_t offset_uint32 = static_cast<uint32_t>(offset);
asapersson@webrtc.orgcfd82df2015-01-22 09:39:59252 counters.transmitted.payload_bytes = offset;
253 counters.transmitted.header_bytes = offset + 1;
254 counters.fec.packets = offset_uint32 + 2;
255 counters.transmitted.padding_bytes = offset + 3;
256 counters.retransmitted.packets = offset_uint32 + 4;
257 counters.transmitted.packets = offset_uint32 + 5;
stefan@webrtc.org58e2d262014-08-14 15:10:49258 callback->DataCountersUpdated(counters, ssrc);
259 }
sprang@webrtc.orgccd42842014-01-07 09:54:34260
261 VideoSendStream::Stats stats = statistics_proxy_->GetStats();
sprang@webrtc.org09315702014-02-07 12:06:29262 ExpectEqual(expected_, stats);
sprang@webrtc.orgccd42842014-01-07 09:54:34263}
264
265TEST_F(SendStatisticsProxyTest, Bitrate) {
266 BitrateStatisticsObserver* observer = statistics_proxy_.get();
asapersson35151f32016-05-03 06:44:01267 for (const auto& ssrc : config_.rtp.ssrcs) {
sprangcd349d92016-07-13 16:11:28268 uint32_t total;
269 uint32_t retransmit;
stefan@webrtc.org168f23f2014-07-11 13:44:02270 // Use ssrc as bitrate_bps to get a unique value for each stream.
sprangcd349d92016-07-13 16:11:28271 total = ssrc;
272 retransmit = ssrc + 1;
stefan@webrtc.org0bae1fa2014-11-05 14:05:29273 observer->Notify(total, retransmit, ssrc);
sprangcd349d92016-07-13 16:11:28274 expected_.substreams[ssrc].total_bitrate_bps = total;
275 expected_.substreams[ssrc].retransmit_bitrate_bps = retransmit;
sprang@webrtc.orgccd42842014-01-07 09:54:34276 }
asapersson35151f32016-05-03 06:44:01277 for (const auto& ssrc : config_.rtp.rtx.ssrcs) {
sprangcd349d92016-07-13 16:11:28278 uint32_t total;
279 uint32_t retransmit;
stefan@webrtc.org58e2d262014-08-14 15:10:49280 // Use ssrc as bitrate_bps to get a unique value for each stream.
sprangcd349d92016-07-13 16:11:28281 total = ssrc;
282 retransmit = ssrc + 1;
stefan@webrtc.org0bae1fa2014-11-05 14:05:29283 observer->Notify(total, retransmit, ssrc);
sprangcd349d92016-07-13 16:11:28284 expected_.substreams[ssrc].total_bitrate_bps = total;
285 expected_.substreams[ssrc].retransmit_bitrate_bps = retransmit;
stefan@webrtc.org58e2d262014-08-14 15:10:49286 }
sprang@webrtc.orgccd42842014-01-07 09:54:34287
288 VideoSendStream::Stats stats = statistics_proxy_->GetStats();
sprang@webrtc.org09315702014-02-07 12:06:29289 ExpectEqual(expected_, stats);
sprang@webrtc.orgccd42842014-01-07 09:54:34290}
291
stefan@webrtc.org168f23f2014-07-11 13:44:02292TEST_F(SendStatisticsProxyTest, SendSideDelay) {
293 SendSideDelayObserver* observer = statistics_proxy_.get();
asapersson35151f32016-05-03 06:44:01294 for (const auto& ssrc : config_.rtp.ssrcs) {
stefan@webrtc.org168f23f2014-07-11 13:44:02295 // Use ssrc as avg_delay_ms and max_delay_ms to get a unique value for each
296 // stream.
297 int avg_delay_ms = ssrc;
298 int max_delay_ms = ssrc + 1;
299 observer->SendSideDelayUpdated(avg_delay_ms, max_delay_ms, ssrc);
300 expected_.substreams[ssrc].avg_delay_ms = avg_delay_ms;
301 expected_.substreams[ssrc].max_delay_ms = max_delay_ms;
302 }
asapersson35151f32016-05-03 06:44:01303 for (const auto& ssrc : config_.rtp.rtx.ssrcs) {
stefan@webrtc.org58e2d262014-08-14 15:10:49304 // Use ssrc as avg_delay_ms and max_delay_ms to get a unique value for each
305 // stream.
306 int avg_delay_ms = ssrc;
307 int max_delay_ms = ssrc + 1;
308 observer->SendSideDelayUpdated(avg_delay_ms, max_delay_ms, ssrc);
309 expected_.substreams[ssrc].avg_delay_ms = avg_delay_ms;
310 expected_.substreams[ssrc].max_delay_ms = max_delay_ms;
311 }
sprang@webrtc.orgccd42842014-01-07 09:54:34312 VideoSendStream::Stats stats = statistics_proxy_->GetStats();
stefan@webrtc.org168f23f2014-07-11 13:44:02313 ExpectEqual(expected_, stats);
sprang@webrtc.orgccd42842014-01-07 09:54:34314}
315
Peter Boströme4499152016-02-05 10:13:28316TEST_F(SendStatisticsProxyTest, OnEncodedFrameTimeMeasured) {
asapersson1aa420b2015-12-07 11:12:22317 const int kEncodeTimeMs = 11;
Peter Boströme4499152016-02-05 10:13:28318 CpuOveruseMetrics metrics;
319 metrics.encode_usage_percent = 80;
320 statistics_proxy_->OnEncodedFrameTimeMeasured(kEncodeTimeMs, metrics);
asapersson1aa420b2015-12-07 11:12:22321
322 VideoSendStream::Stats stats = statistics_proxy_->GetStats();
323 EXPECT_EQ(kEncodeTimeMs, stats.avg_encode_time_ms);
Peter Boströme4499152016-02-05 10:13:28324 EXPECT_EQ(metrics.encode_usage_percent, stats.encode_usage_percent);
asapersson1aa420b2015-12-07 11:12:22325}
326
Pera48ddb72016-09-29 09:48:50327TEST_F(SendStatisticsProxyTest, OnEncoderReconfiguredChangePreferredBitrate) {
328 VideoSendStream::Stats stats = statistics_proxy_->GetStats();
329 EXPECT_EQ(0, stats.preferred_media_bitrate_bps);
330 const int kPreferredMediaBitrateBps = 50;
331
332 VideoEncoderConfig config;
333 statistics_proxy_->OnEncoderReconfigured(config, kPreferredMediaBitrateBps);
334 stats = statistics_proxy_->GetStats();
335 EXPECT_EQ(kPreferredMediaBitrateBps, stats.preferred_media_bitrate_bps);
336}
337
sakal43536c32016-10-24 08:46:43338TEST_F(SendStatisticsProxyTest, OnSendEncodedImageIncreasesFramesEncoded) {
339 EncodedImage encoded_image;
340 CodecSpecificInfo codec_info;
341 EXPECT_EQ(0u, statistics_proxy_->GetStats().frames_encoded);
342 for (uint32_t i = 1; i <= 3; ++i) {
343 statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info);
344 EXPECT_EQ(i, statistics_proxy_->GetStats().frames_encoded);
345 }
346}
347
sakal87da4042016-10-31 13:53:47348TEST_F(SendStatisticsProxyTest, OnSendEncodedImageIncreasesQpSum) {
349 EncodedImage encoded_image;
350 CodecSpecificInfo codec_info;
351 EXPECT_EQ(rtc::Optional<uint64_t>(), statistics_proxy_->GetStats().qp_sum);
352 encoded_image.qp_ = 3;
353 statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info);
354 EXPECT_EQ(rtc::Optional<uint64_t>(3u), statistics_proxy_->GetStats().qp_sum);
355 encoded_image.qp_ = 127;
356 statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info);
357 EXPECT_EQ(rtc::Optional<uint64_t>(130u),
358 statistics_proxy_->GetStats().qp_sum);
359}
360
361TEST_F(SendStatisticsProxyTest, OnSendEncodedImageWithoutQpQpSumWontExist) {
362 EncodedImage encoded_image;
363 CodecSpecificInfo codec_info;
364 encoded_image.qp_ = -1;
365 EXPECT_EQ(rtc::Optional<uint64_t>(), statistics_proxy_->GetStats().qp_sum);
366 statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info);
367 EXPECT_EQ(rtc::Optional<uint64_t>(), statistics_proxy_->GetStats().qp_sum);
368}
369
asapersson59bac1a2016-01-08 07:36:00370TEST_F(SendStatisticsProxyTest, SwitchContentTypeUpdatesHistograms) {
perkj803d97f2016-11-01 18:45:46371 for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i)
asapersson59bac1a2016-01-08 07:36:00372 statistics_proxy_->OnIncomingFrame(kWidth, kHeight);
373
Pera48ddb72016-09-29 09:48:50374 // No switch, stats should not be updated.
375 VideoEncoderConfig config;
376 config.content_type = VideoEncoderConfig::ContentType::kRealtimeVideo;
377 statistics_proxy_->OnEncoderReconfigured(config, 50);
asapersson01d70a32016-05-20 13:29:46378 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.InputWidthInPixels"));
asapersson59bac1a2016-01-08 07:36:00379
380 // Switch to screenshare, real-time stats should be updated.
Pera48ddb72016-09-29 09:48:50381 config.content_type = VideoEncoderConfig::ContentType::kScreen;
382 statistics_proxy_->OnEncoderReconfigured(config, 50);
asapersson01d70a32016-05-20 13:29:46383 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.InputWidthInPixels"));
asapersson59bac1a2016-01-08 07:36:00384}
385
asapersson320e45a2016-11-29 09:40:35386TEST_F(SendStatisticsProxyTest, InputResolutionHistogramsAreUpdated) {
387 for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i)
388 statistics_proxy_->OnIncomingFrame(kWidth, kHeight);
perkj803d97f2016-11-01 18:45:46389
asapersson320e45a2016-11-29 09:40:35390 statistics_proxy_.reset();
391 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.InputWidthInPixels"));
392 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.InputWidthInPixels", kWidth));
393 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.InputHeightInPixels"));
394 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.InputHeightInPixels", kHeight));
395}
396
397TEST_F(SendStatisticsProxyTest, SentResolutionHistogramsAreUpdated) {
398 EncodedImage encoded_image;
399 encoded_image._encodedWidth = kWidth;
400 encoded_image._encodedHeight = kHeight;
401 for (int i = 0; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) {
402 encoded_image._timeStamp = i + 1;
403 statistics_proxy_->OnSendEncodedImage(encoded_image, nullptr);
404 }
405 statistics_proxy_.reset();
406 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.SentWidthInPixels"));
407 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.SentWidthInPixels", kWidth));
408 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.SentHeightInPixels"));
409 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.SentHeightInPixels", kHeight));
410}
411
412TEST_F(SendStatisticsProxyTest, InputFpsHistogramIsUpdated) {
413 const int kFps = 20;
414 const int kMinPeriodicSamples = 6;
415 int frames = kMinPeriodicSamples * kFpsPeriodicIntervalMs * kFps / 1000;
416 for (int i = 0; i <= frames; ++i) {
417 fake_clock_.AdvanceTimeMilliseconds(1000 / kFps);
418 statistics_proxy_->OnIncomingFrame(kWidth, kHeight);
419 }
420 statistics_proxy_.reset();
421 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.InputFramesPerSecond"));
422 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.InputFramesPerSecond", kFps));
423}
424
425TEST_F(SendStatisticsProxyTest, SentFpsHistogramIsUpdated) {
426 EncodedImage encoded_image;
427 const int kFps = 20;
428 const int kMinPeriodicSamples = 6;
429 int frames = kMinPeriodicSamples * kFpsPeriodicIntervalMs * kFps / 1000 + 1;
430 for (int i = 0; i <= frames; ++i) {
431 fake_clock_.AdvanceTimeMilliseconds(1000 / kFps);
432 encoded_image._timeStamp = i + 1;
433 statistics_proxy_->OnSendEncodedImage(encoded_image, nullptr);
434 }
435 statistics_proxy_.reset();
436 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.SentFramesPerSecond"));
437 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.SentFramesPerSecond", kFps));
438}
439
440TEST_F(SendStatisticsProxyTest, InputFpsHistogramExcludesSuspendedTime) {
441 const int kFps = 20;
442 const int kSuspendTimeMs = 10000;
443 const int kMinPeriodicSamples = 6;
444 int frames = kMinPeriodicSamples * kFpsPeriodicIntervalMs * kFps / 1000;
445 for (int i = 0; i < frames; ++i) {
446 fake_clock_.AdvanceTimeMilliseconds(1000 / kFps);
447 statistics_proxy_->OnIncomingFrame(kWidth, kHeight);
448 }
449 // Suspend.
450 statistics_proxy_->OnSuspendChange(true);
451 fake_clock_.AdvanceTimeMilliseconds(kSuspendTimeMs);
452
453 for (int i = 0; i < frames; ++i) {
454 fake_clock_.AdvanceTimeMilliseconds(1000 / kFps);
455 statistics_proxy_->OnIncomingFrame(kWidth, kHeight);
456 }
457 // Suspended time interval should not affect the framerate.
458 statistics_proxy_.reset();
459 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.InputFramesPerSecond"));
460 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.InputFramesPerSecond", kFps));
461}
462
463TEST_F(SendStatisticsProxyTest, SentFpsHistogramExcludesSuspendedTime) {
464 EncodedImage encoded_image;
465 const int kFps = 20;
466 const int kSuspendTimeMs = 10000;
467 const int kMinPeriodicSamples = 6;
468 int frames = kMinPeriodicSamples * kFpsPeriodicIntervalMs * kFps / 1000;
469 for (int i = 0; i <= frames; ++i) {
470 fake_clock_.AdvanceTimeMilliseconds(1000 / kFps);
471 encoded_image._timeStamp = i + 1;
472 statistics_proxy_->OnSendEncodedImage(encoded_image, nullptr);
473 }
474 // Suspend.
475 statistics_proxy_->OnSuspendChange(true);
476 fake_clock_.AdvanceTimeMilliseconds(kSuspendTimeMs);
477
478 for (int i = 0; i <= frames; ++i) {
479 fake_clock_.AdvanceTimeMilliseconds(1000 / kFps);
480 encoded_image._timeStamp = i + 1;
481 statistics_proxy_->OnSendEncodedImage(encoded_image, nullptr);
482 }
483 // Suspended time interval should not affect the framerate.
484 statistics_proxy_.reset();
485 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.SentFramesPerSecond"));
486 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.SentFramesPerSecond", kFps));
487}
488
489TEST_F(SendStatisticsProxyTest, CpuLimitedResolutionUpdated) {
perkj803d97f2016-11-01 18:45:46490 for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i)
491 statistics_proxy_->OnIncomingFrame(kWidth, kHeight);
492
493 statistics_proxy_->OnCpuRestrictedResolutionChanged(true);
494
495 for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i)
496 statistics_proxy_->OnIncomingFrame(kWidth, kHeight);
497
498 statistics_proxy_.reset();
499 EXPECT_EQ(1,
500 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent"));
501 EXPECT_EQ(
502 1, metrics::NumEvents("WebRTC.Video.CpuLimitedResolutionInPercent", 50));
503}
504
asapersson4374a092016-07-27 07:39:09505TEST_F(SendStatisticsProxyTest, LifetimeHistogramIsUpdated) {
506 const int64_t kTimeSec = 3;
507 fake_clock_.AdvanceTimeMilliseconds(kTimeSec * 1000);
508 statistics_proxy_.reset();
509 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.SendStreamLifetimeInSeconds"));
510 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.SendStreamLifetimeInSeconds",
511 kTimeSec));
512}
513
514TEST_F(SendStatisticsProxyTest, CodecTypeHistogramIsUpdated) {
515 fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000);
516 statistics_proxy_.reset();
517 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.Encoder.CodecType"));
518}
519
asapersson66d4b372016-12-19 14:50:53520TEST_F(SendStatisticsProxyTest, PauseEventHistogramIsUpdated) {
521 // First RTP packet sent.
522 UpdateDataCounters(kFirstSsrc);
523
524 // Min runtime has passed.
525 fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000);
526 statistics_proxy_.reset();
527 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.NumberOfPauseEvents"));
528 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.NumberOfPauseEvents", 0));
529}
530
531TEST_F(SendStatisticsProxyTest,
532 PauseEventHistogramIsNotUpdatedIfMinRuntimeHasNotPassed) {
533 // First RTP packet sent.
534 UpdateDataCounters(kFirstSsrc);
535
536 // Min runtime has not passed.
537 fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000 - 1);
538 statistics_proxy_.reset();
539 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.NumberOfPauseEvents"));
540 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.PausedTimeInPercent"));
541}
542
543TEST_F(SendStatisticsProxyTest,
544 PauseEventHistogramIsNotUpdatedIfNoMediaIsSent) {
545 // First RTP packet not sent.
546 fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000);
547 statistics_proxy_.reset();
548 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.NumberOfPauseEvents"));
549}
550
551TEST_F(SendStatisticsProxyTest, NoPauseEvent) {
552 // First RTP packet sent and min runtime passed.
553 UpdateDataCounters(kFirstSsrc);
554
555 // No change. Video: 10000 ms, paused: 0 ms (0%).
556 statistics_proxy_->OnSetEncoderTargetRate(50000);
557 fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000);
558 statistics_proxy_->OnSetEncoderTargetRate(0); // VideoSendStream::Stop
559
560 statistics_proxy_.reset();
561 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.NumberOfPauseEvents"));
562 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.NumberOfPauseEvents", 0));
563 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.PausedTimeInPercent"));
564 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.PausedTimeInPercent", 0));
565}
566
567TEST_F(SendStatisticsProxyTest, OnePauseEvent) {
568 // First RTP packet sent and min runtime passed.
569 UpdateDataCounters(kFirstSsrc);
570
571 // One change. Video: 7000 ms, paused: 3000 ms (30%).
572 statistics_proxy_->OnSetEncoderTargetRate(50000);
573 fake_clock_.AdvanceTimeMilliseconds(7000);
574 statistics_proxy_->OnSetEncoderTargetRate(0);
575 fake_clock_.AdvanceTimeMilliseconds(3000);
576 statistics_proxy_->OnSetEncoderTargetRate(0); // VideoSendStream::Stop
577
578 statistics_proxy_.reset();
579 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.NumberOfPauseEvents"));
580 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.NumberOfPauseEvents", 1));
581 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.PausedTimeInPercent"));
582 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.PausedTimeInPercent", 30));
583}
584
585TEST_F(SendStatisticsProxyTest, TwoPauseEvents) {
586 // First RTP packet sent.
587 UpdateDataCounters(kFirstSsrc);
588
589 // Two changes. Video: 19000 ms, paused: 1000 ms (5%).
590 statistics_proxy_->OnSetEncoderTargetRate(0);
591 fake_clock_.AdvanceTimeMilliseconds(1000);
592 statistics_proxy_->OnSetEncoderTargetRate(50000); // Starts on bitrate > 0.
593 fake_clock_.AdvanceTimeMilliseconds(7000);
594 statistics_proxy_->OnSetEncoderTargetRate(60000);
595 fake_clock_.AdvanceTimeMilliseconds(3000);
596 statistics_proxy_->OnSetEncoderTargetRate(0);
597 fake_clock_.AdvanceTimeMilliseconds(250);
598 statistics_proxy_->OnSetEncoderTargetRate(0);
599 fake_clock_.AdvanceTimeMilliseconds(750);
600 statistics_proxy_->OnSetEncoderTargetRate(60000);
601 fake_clock_.AdvanceTimeMilliseconds(5000);
602 statistics_proxy_->OnSetEncoderTargetRate(50000);
603 fake_clock_.AdvanceTimeMilliseconds(4000);
604 statistics_proxy_->OnSetEncoderTargetRate(0); // VideoSendStream::Stop
605
606 statistics_proxy_.reset();
607 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.NumberOfPauseEvents"));
608 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.NumberOfPauseEvents", 2));
609 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.PausedTimeInPercent"));
610 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.PausedTimeInPercent", 5));
611}
612
613TEST_F(SendStatisticsProxyTest,
614 PausedTimeHistogramIsNotUpdatedIfMinRuntimeHasNotPassed) {
615 // First RTP packet sent.
616 UpdateDataCounters(kFirstSsrc);
617 fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000);
618
619 // Min runtime has not passed.
620 statistics_proxy_->OnSetEncoderTargetRate(50000);
621 fake_clock_.AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000 - 1);
622 statistics_proxy_->OnSetEncoderTargetRate(0); // VideoSendStream::Stop
623
624 statistics_proxy_.reset();
625 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.PausedTimeInPercent"));
626}
627
asapersson118ef002016-03-31 07:00:19628TEST_F(SendStatisticsProxyTest, VerifyQpHistogramStats_Vp8) {
asapersson118ef002016-03-31 07:00:19629 EncodedImage encoded_image;
kjellander02b3d272016-04-20 12:05:54630 CodecSpecificInfo codec_info;
631 codec_info.codecType = kVideoCodecVP8;
asapersson118ef002016-03-31 07:00:19632
perkj803d97f2016-11-01 18:45:46633 for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) {
kjellander02b3d272016-04-20 12:05:54634 codec_info.codecSpecific.VP8.simulcastIdx = 0;
asapersson118ef002016-03-31 07:00:19635 encoded_image.qp_ = kQpIdx0;
kjellander02b3d272016-04-20 12:05:54636 statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info);
637 codec_info.codecSpecific.VP8.simulcastIdx = 1;
asapersson118ef002016-03-31 07:00:19638 encoded_image.qp_ = kQpIdx1;
kjellander02b3d272016-04-20 12:05:54639 statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info);
asapersson118ef002016-03-31 07:00:19640 }
641 statistics_proxy_.reset();
asapersson01d70a32016-05-20 13:29:46642 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.Encoded.Qp.Vp8.S0"));
643 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.Encoded.Qp.Vp8.S0", kQpIdx0));
644 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.Encoded.Qp.Vp8.S1"));
645 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.Encoded.Qp.Vp8.S1", kQpIdx1));
asapersson118ef002016-03-31 07:00:19646}
647
648TEST_F(SendStatisticsProxyTest, VerifyQpHistogramStats_Vp8OneSsrc) {
649 VideoSendStream::Config config(nullptr);
650 config.rtp.ssrcs.push_back(kFirstSsrc);
651 statistics_proxy_.reset(new SendStatisticsProxy(
652 &fake_clock_, config, VideoEncoderConfig::ContentType::kRealtimeVideo));
653
asapersson118ef002016-03-31 07:00:19654 EncodedImage encoded_image;
kjellander02b3d272016-04-20 12:05:54655 CodecSpecificInfo codec_info;
656 codec_info.codecType = kVideoCodecVP8;
asapersson118ef002016-03-31 07:00:19657
perkj803d97f2016-11-01 18:45:46658 for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) {
kjellander02b3d272016-04-20 12:05:54659 codec_info.codecSpecific.VP8.simulcastIdx = 0;
asapersson118ef002016-03-31 07:00:19660 encoded_image.qp_ = kQpIdx0;
kjellander02b3d272016-04-20 12:05:54661 statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info);
asapersson118ef002016-03-31 07:00:19662 }
663 statistics_proxy_.reset();
asapersson01d70a32016-05-20 13:29:46664 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.Encoded.Qp.Vp8"));
665 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.Encoded.Qp.Vp8", kQpIdx0));
asapersson118ef002016-03-31 07:00:19666}
667
asapersson5265fed2016-04-18 09:58:47668TEST_F(SendStatisticsProxyTest, VerifyQpHistogramStats_Vp9) {
asapersson5265fed2016-04-18 09:58:47669 EncodedImage encoded_image;
kjellander02b3d272016-04-20 12:05:54670 CodecSpecificInfo codec_info;
671 codec_info.codecType = kVideoCodecVP9;
672 codec_info.codecSpecific.VP9.num_spatial_layers = 2;
asapersson5265fed2016-04-18 09:58:47673
perkj803d97f2016-11-01 18:45:46674 for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) {
asapersson5265fed2016-04-18 09:58:47675 encoded_image.qp_ = kQpIdx0;
kjellander02b3d272016-04-20 12:05:54676 codec_info.codecSpecific.VP9.spatial_idx = 0;
677 statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info);
asapersson5265fed2016-04-18 09:58:47678 encoded_image.qp_ = kQpIdx1;
kjellander02b3d272016-04-20 12:05:54679 codec_info.codecSpecific.VP9.spatial_idx = 1;
680 statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info);
asapersson5265fed2016-04-18 09:58:47681 }
682 statistics_proxy_.reset();
asapersson01d70a32016-05-20 13:29:46683 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.Encoded.Qp.Vp9.S0"));
684 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.Encoded.Qp.Vp9.S0", kQpIdx0));
685 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.Encoded.Qp.Vp9.S1"));
686 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.Encoded.Qp.Vp9.S1", kQpIdx1));
asapersson5265fed2016-04-18 09:58:47687}
688
689TEST_F(SendStatisticsProxyTest, VerifyQpHistogramStats_Vp9OneSpatialLayer) {
690 VideoSendStream::Config config(nullptr);
691 config.rtp.ssrcs.push_back(kFirstSsrc);
692 statistics_proxy_.reset(new SendStatisticsProxy(
693 &fake_clock_, config, VideoEncoderConfig::ContentType::kRealtimeVideo));
694
asapersson5265fed2016-04-18 09:58:47695 EncodedImage encoded_image;
kjellander02b3d272016-04-20 12:05:54696 CodecSpecificInfo codec_info;
697 codec_info.codecType = kVideoCodecVP9;
698 codec_info.codecSpecific.VP9.num_spatial_layers = 1;
asapersson5265fed2016-04-18 09:58:47699
perkj803d97f2016-11-01 18:45:46700 for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) {
asapersson5265fed2016-04-18 09:58:47701 encoded_image.qp_ = kQpIdx0;
kjellander02b3d272016-04-20 12:05:54702 codec_info.codecSpecific.VP9.spatial_idx = 0;
703 statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info);
asapersson5265fed2016-04-18 09:58:47704 }
705 statistics_proxy_.reset();
asapersson01d70a32016-05-20 13:29:46706 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.Encoded.Qp.Vp9"));
707 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.Encoded.Qp.Vp9", kQpIdx0));
asapersson5265fed2016-04-18 09:58:47708}
709
asapersson827cab32016-11-02 16:08:47710TEST_F(SendStatisticsProxyTest, VerifyQpHistogramStats_H264) {
711 EncodedImage encoded_image;
712 CodecSpecificInfo codec_info;
713 codec_info.codecType = kVideoCodecH264;
714
715 for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) {
716 encoded_image.qp_ = kQpIdx0;
717 statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info);
718 }
719 statistics_proxy_.reset();
720 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.Encoded.Qp.H264"));
721 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.Encoded.Qp.H264", kQpIdx0));
722}
723
asapersson4ee70462016-10-31 11:05:12724TEST_F(SendStatisticsProxyTest,
725 BandwidthLimitedHistogramsNotUpdatedWhenDisabled) {
726 EncodedImage encoded_image;
727 // encoded_image.adapt_reason_.bw_resolutions_disabled by default: -1
perkj803d97f2016-11-01 18:45:46728 for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i)
asapersson4ee70462016-10-31 11:05:12729 statistics_proxy_->OnSendEncodedImage(encoded_image, nullptr);
730
731 // Histograms are updated when the statistics_proxy_ is deleted.
732 statistics_proxy_.reset();
733 EXPECT_EQ(0, metrics::NumSamples(
734 "WebRTC.Video.BandwidthLimitedResolutionInPercent"));
735 EXPECT_EQ(0, metrics::NumSamples(
736 "WebRTC.Video.BandwidthLimitedResolutionsDisabled"));
737}
738
739TEST_F(SendStatisticsProxyTest,
740 BandwidthLimitedHistogramsUpdatedWhenEnabled_NoResolutionDisabled) {
741 const int kResolutionsDisabled = 0;
742 EncodedImage encoded_image;
743 encoded_image.adapt_reason_.bw_resolutions_disabled = kResolutionsDisabled;
perkj803d97f2016-11-01 18:45:46744 for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i)
asapersson4ee70462016-10-31 11:05:12745 statistics_proxy_->OnSendEncodedImage(encoded_image, nullptr);
746
747 // Histograms are updated when the statistics_proxy_ is deleted.
748 statistics_proxy_.reset();
749 EXPECT_EQ(1, metrics::NumSamples(
750 "WebRTC.Video.BandwidthLimitedResolutionInPercent"));
751 EXPECT_EQ(1, metrics::NumEvents(
752 "WebRTC.Video.BandwidthLimitedResolutionInPercent", 0));
753 // No resolution disabled.
754 EXPECT_EQ(0, metrics::NumSamples(
755 "WebRTC.Video.BandwidthLimitedResolutionsDisabled"));
756}
757
758TEST_F(SendStatisticsProxyTest,
759 BandwidthLimitedHistogramsUpdatedWhenEnabled_OneResolutionDisabled) {
760 const int kResolutionsDisabled = 1;
761 EncodedImage encoded_image;
762 encoded_image.adapt_reason_.bw_resolutions_disabled = kResolutionsDisabled;
perkj803d97f2016-11-01 18:45:46763 for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i)
asapersson4ee70462016-10-31 11:05:12764 statistics_proxy_->OnSendEncodedImage(encoded_image, nullptr);
765
766 // Histograms are updated when the statistics_proxy_ is deleted.
767 statistics_proxy_.reset();
768 EXPECT_EQ(1, metrics::NumSamples(
769 "WebRTC.Video.BandwidthLimitedResolutionInPercent"));
770 EXPECT_EQ(1, metrics::NumEvents(
771 "WebRTC.Video.BandwidthLimitedResolutionInPercent", 100));
772 // Resolutions disabled.
773 EXPECT_EQ(1, metrics::NumSamples(
774 "WebRTC.Video.BandwidthLimitedResolutionsDisabled"));
775 EXPECT_EQ(
776 1, metrics::NumEvents("WebRTC.Video.BandwidthLimitedResolutionsDisabled",
777 kResolutionsDisabled));
778}
779
780TEST_F(SendStatisticsProxyTest,
781 QualityLimitedHistogramsNotUpdatedWhenDisabled) {
782 EncodedImage encoded_image;
kthelgason0cd27ba2016-12-19 14:32:16783 statistics_proxy_->SetResolutionRestrictionStats(false /* scaling_enabled */,
784 0, 0);
perkj803d97f2016-11-01 18:45:46785 for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i)
kthelgason0cd27ba2016-12-19 14:32:16786 statistics_proxy_->OnSendEncodedImage(encoded_image, &kDefaultCodecInfo);
asapersson4ee70462016-10-31 11:05:12787
788 // Histograms are updated when the statistics_proxy_ is deleted.
789 statistics_proxy_.reset();
790 EXPECT_EQ(
791 0, metrics::NumSamples("WebRTC.Video.QualityLimitedResolutionInPercent"));
792 EXPECT_EQ(0, metrics::NumSamples(
793 "WebRTC.Video.QualityLimitedResolutionDownscales"));
794}
795
796TEST_F(SendStatisticsProxyTest,
797 QualityLimitedHistogramsUpdatedWhenEnabled_NoResolutionDownscale) {
asapersson4ee70462016-10-31 11:05:12798 EncodedImage encoded_image;
perkj803d97f2016-11-01 18:45:46799 for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i)
kthelgason0cd27ba2016-12-19 14:32:16800 statistics_proxy_->OnSendEncodedImage(encoded_image, &kDefaultCodecInfo);
asapersson4ee70462016-10-31 11:05:12801
802 // Histograms are updated when the statistics_proxy_ is deleted.
803 statistics_proxy_.reset();
804 EXPECT_EQ(
805 1, metrics::NumSamples("WebRTC.Video.QualityLimitedResolutionInPercent"));
806 EXPECT_EQ(1, metrics::NumEvents(
807 "WebRTC.Video.QualityLimitedResolutionInPercent", 0));
808 // No resolution downscale.
809 EXPECT_EQ(0, metrics::NumSamples(
810 "WebRTC.Video.QualityLimitedResolutionDownscales"));
811}
812
813TEST_F(SendStatisticsProxyTest,
814 QualityLimitedHistogramsUpdatedWhenEnabled_TwoResolutionDownscales) {
815 const int kDownscales = 2;
816 EncodedImage encoded_image;
kthelgason0cd27ba2016-12-19 14:32:16817 statistics_proxy_->OnQualityRestrictedResolutionChanged(kDownscales);
perkj803d97f2016-11-01 18:45:46818 for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i)
kthelgason0cd27ba2016-12-19 14:32:16819 statistics_proxy_->OnSendEncodedImage(encoded_image, &kDefaultCodecInfo);
asapersson4ee70462016-10-31 11:05:12820 // Histograms are updated when the statistics_proxy_ is deleted.
821 statistics_proxy_.reset();
822 EXPECT_EQ(
823 1, metrics::NumSamples("WebRTC.Video.QualityLimitedResolutionInPercent"));
824 EXPECT_EQ(1, metrics::NumEvents(
825 "WebRTC.Video.QualityLimitedResolutionInPercent", 100));
826 // Resolution downscales.
827 EXPECT_EQ(1, metrics::NumSamples(
828 "WebRTC.Video.QualityLimitedResolutionDownscales"));
829 EXPECT_EQ(
830 1, metrics::NumEvents("WebRTC.Video.QualityLimitedResolutionDownscales",
831 kDownscales));
832}
833
834TEST_F(SendStatisticsProxyTest, GetStatsReportsBandwidthLimitedResolution) {
835 // Initially false.
836 EXPECT_FALSE(statistics_proxy_->GetStats().bw_limited_resolution);
837 // No resolution scale by default.
838 EncodedImage encoded_image;
839 statistics_proxy_->OnSendEncodedImage(encoded_image, nullptr);
840 EXPECT_FALSE(statistics_proxy_->GetStats().bw_limited_resolution);
kthelgason0cd27ba2016-12-19 14:32:16841
842 // Simulcast disabled resolutions
843 encoded_image.adapt_reason_.bw_resolutions_disabled = 1;
844 statistics_proxy_->OnSendEncodedImage(encoded_image, nullptr);
845 EXPECT_TRUE(statistics_proxy_->GetStats().bw_limited_resolution);
846
asapersson4ee70462016-10-31 11:05:12847 encoded_image.adapt_reason_.bw_resolutions_disabled = 0;
asapersson4ee70462016-10-31 11:05:12848 statistics_proxy_->OnSendEncodedImage(encoded_image, nullptr);
849 EXPECT_FALSE(statistics_proxy_->GetStats().bw_limited_resolution);
kthelgason0cd27ba2016-12-19 14:32:16850
851 // Resolution scaled due to quality.
852 statistics_proxy_->OnQualityRestrictedResolutionChanged(1);
asapersson4ee70462016-10-31 11:05:12853 statistics_proxy_->OnSendEncodedImage(encoded_image, nullptr);
854 EXPECT_TRUE(statistics_proxy_->GetStats().bw_limited_resolution);
855}
856
asapersson66d4b372016-12-19 14:50:53857TEST_F(SendStatisticsProxyTest, GetStatsReportsTargetMediaBitrate) {
858 // Initially zero.
859 EXPECT_EQ(0, statistics_proxy_->GetStats().target_media_bitrate_bps);
860
861 const int kBitrate = 100000;
862 statistics_proxy_->OnSetEncoderTargetRate(kBitrate);
863 EXPECT_EQ(kBitrate, statistics_proxy_->GetStats().target_media_bitrate_bps);
864
865 statistics_proxy_->OnSetEncoderTargetRate(0);
866 EXPECT_EQ(0, statistics_proxy_->GetStats().target_media_bitrate_bps);
867}
868
sprang@webrtc.orgccd42842014-01-07 09:54:34869TEST_F(SendStatisticsProxyTest, NoSubstreams) {
pbos@webrtc.org49096de2015-02-24 22:37:52870 uint32_t excluded_ssrc =
stefan@webrtc.org58e2d262014-08-14 15:10:49871 std::max(
872 *std::max_element(config_.rtp.ssrcs.begin(), config_.rtp.ssrcs.end()),
873 *std::max_element(config_.rtp.rtx.ssrcs.begin(),
874 config_.rtp.rtx.ssrcs.end())) +
875 1;
sprang@webrtc.orgccd42842014-01-07 09:54:34876 // From RtcpStatisticsCallback.
877 RtcpStatistics rtcp_stats;
878 RtcpStatisticsCallback* rtcp_callback = statistics_proxy_.get();
pbos@webrtc.org49096de2015-02-24 22:37:52879 rtcp_callback->StatisticsUpdated(rtcp_stats, excluded_ssrc);
sprang@webrtc.orgccd42842014-01-07 09:54:34880
881 // From BitrateStatisticsObserver.
sprangcd349d92016-07-13 16:11:28882 uint32_t total = 0;
883 uint32_t retransmit = 0;
sprang@webrtc.orgccd42842014-01-07 09:54:34884 BitrateStatisticsObserver* bitrate_observer = statistics_proxy_.get();
pbos@webrtc.org49096de2015-02-24 22:37:52885 bitrate_observer->Notify(total, retransmit, excluded_ssrc);
sprang@webrtc.orgccd42842014-01-07 09:54:34886
887 // From FrameCountObserver.
888 FrameCountObserver* fps_observer = statistics_proxy_.get();
pbos@webrtc.orgce4e9a32014-12-18 13:50:16889 FrameCounts frame_counts;
890 frame_counts.key_frames = 1;
pbos@webrtc.org49096de2015-02-24 22:37:52891 fps_observer->FrameCountUpdated(frame_counts, excluded_ssrc);
sprang@webrtc.orgccd42842014-01-07 09:54:34892
893 VideoSendStream::Stats stats = statistics_proxy_->GetStats();
894 EXPECT_TRUE(stats.substreams.empty());
895}
896
pbos@webrtc.org273a4142014-12-01 15:23:21897TEST_F(SendStatisticsProxyTest, EncodedResolutionTimesOut) {
898 static const int kEncodedWidth = 123;
899 static const int kEncodedHeight = 81;
900 EncodedImage encoded_image;
901 encoded_image._encodedWidth = kEncodedWidth;
902 encoded_image._encodedHeight = kEncodedHeight;
903
kjellander02b3d272016-04-20 12:05:54904 CodecSpecificInfo codec_info;
905 codec_info.codecType = kVideoCodecVP8;
906 codec_info.codecSpecific.VP8.simulcastIdx = 0;
pbos@webrtc.org273a4142014-12-01 15:23:21907
kjellander02b3d272016-04-20 12:05:54908 statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info);
909 codec_info.codecSpecific.VP8.simulcastIdx = 1;
910 statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info);
pbos@webrtc.org273a4142014-12-01 15:23:21911
912 VideoSendStream::Stats stats = statistics_proxy_->GetStats();
pbos@webrtc.org09c77b92015-02-25 10:42:16913 EXPECT_EQ(kEncodedWidth, stats.substreams[config_.rtp.ssrcs[0]].width);
914 EXPECT_EQ(kEncodedHeight, stats.substreams[config_.rtp.ssrcs[0]].height);
915 EXPECT_EQ(kEncodedWidth, stats.substreams[config_.rtp.ssrcs[1]].width);
916 EXPECT_EQ(kEncodedHeight, stats.substreams[config_.rtp.ssrcs[1]].height);
pbos@webrtc.org273a4142014-12-01 15:23:21917
918 // Forward almost to timeout, this should not have removed stats.
919 fake_clock_.AdvanceTimeMilliseconds(SendStatisticsProxy::kStatsTimeoutMs - 1);
920 stats = statistics_proxy_->GetStats();
pbos@webrtc.org09c77b92015-02-25 10:42:16921 EXPECT_EQ(kEncodedWidth, stats.substreams[config_.rtp.ssrcs[0]].width);
922 EXPECT_EQ(kEncodedHeight, stats.substreams[config_.rtp.ssrcs[0]].height);
pbos@webrtc.org273a4142014-12-01 15:23:21923
924 // Update the first SSRC with bogus RTCP stats to make sure that encoded
925 // resolution still times out (no global timeout for all stats).
926 RtcpStatistics rtcp_statistics;
927 RtcpStatisticsCallback* rtcp_stats = statistics_proxy_.get();
928 rtcp_stats->StatisticsUpdated(rtcp_statistics, config_.rtp.ssrcs[0]);
929
930 // Report stats for second SSRC to make sure it's not outdated along with the
931 // first SSRC.
kjellander02b3d272016-04-20 12:05:54932 codec_info.codecSpecific.VP8.simulcastIdx = 1;
933 statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info);
pbos@webrtc.org273a4142014-12-01 15:23:21934
935 // Forward 1 ms, reach timeout, substream 0 should have no resolution
936 // reported, but substream 1 should.
937 fake_clock_.AdvanceTimeMilliseconds(1);
938 stats = statistics_proxy_->GetStats();
pbos@webrtc.org09c77b92015-02-25 10:42:16939 EXPECT_EQ(0, stats.substreams[config_.rtp.ssrcs[0]].width);
940 EXPECT_EQ(0, stats.substreams[config_.rtp.ssrcs[0]].height);
941 EXPECT_EQ(kEncodedWidth, stats.substreams[config_.rtp.ssrcs[1]].width);
942 EXPECT_EQ(kEncodedHeight, stats.substreams[config_.rtp.ssrcs[1]].height);
pbos@webrtc.org273a4142014-12-01 15:23:21943}
944
Peter Boström20f3f942015-05-15 09:33:39945TEST_F(SendStatisticsProxyTest, ClearsResolutionFromInactiveSsrcs) {
946 static const int kEncodedWidth = 123;
947 static const int kEncodedHeight = 81;
948 EncodedImage encoded_image;
949 encoded_image._encodedWidth = kEncodedWidth;
950 encoded_image._encodedHeight = kEncodedHeight;
951
kjellander02b3d272016-04-20 12:05:54952 CodecSpecificInfo codec_info;
953 codec_info.codecType = kVideoCodecVP8;
954 codec_info.codecSpecific.VP8.simulcastIdx = 0;
Peter Boström20f3f942015-05-15 09:33:39955
kjellander02b3d272016-04-20 12:05:54956 statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info);
957 codec_info.codecSpecific.VP8.simulcastIdx = 1;
958 statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info);
Peter Boström20f3f942015-05-15 09:33:39959
960 statistics_proxy_->OnInactiveSsrc(config_.rtp.ssrcs[1]);
961 VideoSendStream::Stats stats = statistics_proxy_->GetStats();
962 EXPECT_EQ(kEncodedWidth, stats.substreams[config_.rtp.ssrcs[0]].width);
963 EXPECT_EQ(kEncodedHeight, stats.substreams[config_.rtp.ssrcs[0]].height);
964 EXPECT_EQ(0, stats.substreams[config_.rtp.ssrcs[1]].width);
965 EXPECT_EQ(0, stats.substreams[config_.rtp.ssrcs[1]].height);
966}
967
968TEST_F(SendStatisticsProxyTest, ClearsBitratesFromInactiveSsrcs) {
sprangcd349d92016-07-13 16:11:28969 uint32_t bitrate = 42;
Peter Boström20f3f942015-05-15 09:33:39970 BitrateStatisticsObserver* observer = statistics_proxy_.get();
971 observer->Notify(bitrate, bitrate, config_.rtp.ssrcs[0]);
972 observer->Notify(bitrate, bitrate, config_.rtp.ssrcs[1]);
973
974 statistics_proxy_->OnInactiveSsrc(config_.rtp.ssrcs[1]);
975
976 VideoSendStream::Stats stats = statistics_proxy_->GetStats();
sprangcd349d92016-07-13 16:11:28977 EXPECT_EQ(static_cast<int>(bitrate),
Peter Boström20f3f942015-05-15 09:33:39978 stats.substreams[config_.rtp.ssrcs[0]].total_bitrate_bps);
sprangcd349d92016-07-13 16:11:28979 EXPECT_EQ(static_cast<int>(bitrate),
Peter Boström20f3f942015-05-15 09:33:39980 stats.substreams[config_.rtp.ssrcs[0]].retransmit_bitrate_bps);
981 EXPECT_EQ(0, stats.substreams[config_.rtp.ssrcs[1]].total_bitrate_bps);
982 EXPECT_EQ(0, stats.substreams[config_.rtp.ssrcs[1]].retransmit_bitrate_bps);
983}
984
sprang07fb9be2016-02-24 15:55:00985TEST_F(SendStatisticsProxyTest, ResetsRtcpCountersOnContentChange) {
986 RtcpPacketTypeCounterObserver* proxy =
987 static_cast<RtcpPacketTypeCounterObserver*>(statistics_proxy_.get());
988 RtcpPacketTypeCounter counters;
989 counters.first_packet_time_ms = fake_clock_.TimeInMilliseconds();
990 proxy->RtcpPacketTypesCounterUpdated(kFirstSsrc, counters);
991 proxy->RtcpPacketTypesCounterUpdated(kSecondSsrc, counters);
992
993 fake_clock_.AdvanceTimeMilliseconds(1000 * metrics::kMinRunTimeInSeconds);
994
995 counters.nack_packets += 1 * metrics::kMinRunTimeInSeconds;
996 counters.fir_packets += 2 * metrics::kMinRunTimeInSeconds;
997 counters.pli_packets += 3 * metrics::kMinRunTimeInSeconds;
998 counters.unique_nack_requests += 4 * metrics::kMinRunTimeInSeconds;
999 counters.nack_requests += 5 * metrics::kMinRunTimeInSeconds;
1000
1001 proxy->RtcpPacketTypesCounterUpdated(kFirstSsrc, counters);
1002 proxy->RtcpPacketTypesCounterUpdated(kSecondSsrc, counters);
1003
1004 // Changing content type causes histograms to be reported.
Pera48ddb72016-09-29 09:48:501005 VideoEncoderConfig config;
1006 config.content_type = VideoEncoderConfig::ContentType::kScreen;
1007 statistics_proxy_->OnEncoderReconfigured(config, 50);
sprang07fb9be2016-02-24 15:55:001008
asapersson01d70a32016-05-20 13:29:461009 EXPECT_EQ(1,
1010 metrics::NumSamples("WebRTC.Video.NackPacketsReceivedPerMinute"));
1011 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.FirPacketsReceivedPerMinute"));
1012 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.PliPacketsReceivedPerMinute"));
1013 EXPECT_EQ(1, metrics::NumSamples(
sprang07fb9be2016-02-24 15:55:001014 "WebRTC.Video.UniqueNackRequestsReceivedInPercent"));
1015
1016 const int kRate = 60 * 2; // Packets per minute with two streams.
1017
asapersson01d70a32016-05-20 13:29:461018 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.NackPacketsReceivedPerMinute",
1019 1 * kRate));
1020 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.FirPacketsReceivedPerMinute",
1021 2 * kRate));
1022 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.PliPacketsReceivedPerMinute",
1023 3 * kRate));
1024 EXPECT_EQ(
1025 1, metrics::NumEvents("WebRTC.Video.UniqueNackRequestsReceivedInPercent",
1026 4 * 100 / 5));
sprang07fb9be2016-02-24 15:55:001027
1028 // New start time but same counter values.
1029 proxy->RtcpPacketTypesCounterUpdated(kFirstSsrc, counters);
1030 proxy->RtcpPacketTypesCounterUpdated(kSecondSsrc, counters);
1031
1032 fake_clock_.AdvanceTimeMilliseconds(1000 * metrics::kMinRunTimeInSeconds);
1033
1034 counters.nack_packets += 1 * metrics::kMinRunTimeInSeconds;
1035 counters.fir_packets += 2 * metrics::kMinRunTimeInSeconds;
1036 counters.pli_packets += 3 * metrics::kMinRunTimeInSeconds;
1037 counters.unique_nack_requests += 4 * metrics::kMinRunTimeInSeconds;
1038 counters.nack_requests += 5 * metrics::kMinRunTimeInSeconds;
1039
1040 proxy->RtcpPacketTypesCounterUpdated(kFirstSsrc, counters);
1041 proxy->RtcpPacketTypesCounterUpdated(kSecondSsrc, counters);
1042
1043 SetUp(); // Reset stats proxy also causes histograms to be reported.
1044
asapersson01d70a32016-05-20 13:29:461045 EXPECT_EQ(1, metrics::NumSamples(
sprang07fb9be2016-02-24 15:55:001046 "WebRTC.Video.Screenshare.NackPacketsReceivedPerMinute"));
asapersson01d70a32016-05-20 13:29:461047 EXPECT_EQ(1, metrics::NumSamples(
sprang07fb9be2016-02-24 15:55:001048 "WebRTC.Video.Screenshare.FirPacketsReceivedPerMinute"));
asapersson01d70a32016-05-20 13:29:461049 EXPECT_EQ(1, metrics::NumSamples(
sprang07fb9be2016-02-24 15:55:001050 "WebRTC.Video.Screenshare.PliPacketsReceivedPerMinute"));
1051 EXPECT_EQ(
asapersson01d70a32016-05-20 13:29:461052 1, metrics::NumSamples(
sprang07fb9be2016-02-24 15:55:001053 "WebRTC.Video.Screenshare.UniqueNackRequestsReceivedInPercent"));
1054
asapersson01d70a32016-05-20 13:29:461055 EXPECT_EQ(1, metrics::NumEvents(
1056 "WebRTC.Video.Screenshare.NackPacketsReceivedPerMinute",
1057 1 * kRate));
1058 EXPECT_EQ(1, metrics::NumEvents(
1059 "WebRTC.Video.Screenshare.FirPacketsReceivedPerMinute",
1060 2 * kRate));
1061 EXPECT_EQ(1, metrics::NumEvents(
1062 "WebRTC.Video.Screenshare.PliPacketsReceivedPerMinute",
1063 3 * kRate));
1064 EXPECT_EQ(1,
1065 metrics::NumEvents(
1066 "WebRTC.Video.Screenshare.UniqueNackRequestsReceivedInPercent",
1067 4 * 100 / 5));
sprang07fb9be2016-02-24 15:55:001068}
1069
asaperssona6a699a2016-11-25 11:52:461070TEST_F(SendStatisticsProxyTest, GetStatsReportsIsFlexFec) {
1071 statistics_proxy_.reset(
1072 new SendStatisticsProxy(&fake_clock_, GetTestConfigWithFlexFec(),
1073 VideoEncoderConfig::ContentType::kRealtimeVideo));
1074
1075 StreamDataCountersCallback* proxy =
1076 static_cast<StreamDataCountersCallback*>(statistics_proxy_.get());
1077 StreamDataCounters counters;
1078 proxy->DataCountersUpdated(counters, kFirstSsrc);
1079 proxy->DataCountersUpdated(counters, kFlexFecSsrc);
1080
1081 EXPECT_FALSE(GetStreamStats(kFirstSsrc).is_flexfec);
1082 EXPECT_TRUE(GetStreamStats(kFlexFecSsrc).is_flexfec);
1083}
1084
1085TEST_F(SendStatisticsProxyTest, SendBitratesAreReportedWithFlexFecEnabled) {
1086 statistics_proxy_.reset(
1087 new SendStatisticsProxy(&fake_clock_, GetTestConfigWithFlexFec(),
1088 VideoEncoderConfig::ContentType::kRealtimeVideo));
1089
1090 StreamDataCountersCallback* proxy =
1091 static_cast<StreamDataCountersCallback*>(statistics_proxy_.get());
1092
1093 StreamDataCounters counters;
1094 StreamDataCounters rtx_counters;
1095 proxy->DataCountersUpdated(counters, kFirstSsrc);
1096 proxy->DataCountersUpdated(counters, kSecondSsrc);
1097 proxy->DataCountersUpdated(rtx_counters, kFirstRtxSsrc);
1098 proxy->DataCountersUpdated(rtx_counters, kSecondRtxSsrc);
1099 proxy->DataCountersUpdated(counters, kFlexFecSsrc);
1100
1101 counters.transmitted.header_bytes = 5000;
1102 counters.transmitted.packets = 20;
1103 counters.transmitted.padding_bytes = 10000;
1104 counters.transmitted.payload_bytes = 20000;
1105 counters.retransmitted.header_bytes = 400;
1106 counters.retransmitted.packets = 2;
1107 counters.retransmitted.padding_bytes = 1000;
1108 counters.retransmitted.payload_bytes = 2000;
1109 counters.fec = counters.retransmitted;
1110 rtx_counters.transmitted = counters.transmitted;
1111
1112 fake_clock_.AdvanceTimeMilliseconds(1000 * metrics::kMinRunTimeInSeconds);
1113 proxy->DataCountersUpdated(counters, kFirstSsrc);
1114 proxy->DataCountersUpdated(counters, kSecondSsrc);
1115 proxy->DataCountersUpdated(rtx_counters, kFirstRtxSsrc);
1116 proxy->DataCountersUpdated(rtx_counters, kSecondRtxSsrc);
1117 proxy->DataCountersUpdated(counters, kFlexFecSsrc);
1118
1119 // Reset stats proxy causes histograms to be reported.
1120 statistics_proxy_.reset();
1121 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.BitrateSentInKbps"));
1122 EXPECT_EQ(1,
1123 metrics::NumEvents(
1124 "WebRTC.Video.BitrateSentInKbps",
1125 static_cast<int>((counters.transmitted.TotalBytes() * 4 * 8) /
1126 metrics::kMinRunTimeInSeconds / 1000)));
1127
1128 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.MediaBitrateSentInKbps"));
1129 EXPECT_EQ(1, metrics::NumEvents(
1130 "WebRTC.Video.MediaBitrateSentInKbps",
1131 static_cast<int>((counters.MediaPayloadBytes() * 2 * 8) /
1132 metrics::kMinRunTimeInSeconds / 1000)));
1133
1134 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.PaddingBitrateSentInKbps"));
1135 EXPECT_EQ(1,
1136 metrics::NumEvents(
1137 "WebRTC.Video.PaddingBitrateSentInKbps",
1138 static_cast<int>((counters.transmitted.padding_bytes * 4 * 8) /
1139 metrics::kMinRunTimeInSeconds / 1000)));
1140
1141 EXPECT_EQ(1,
1142 metrics::NumSamples("WebRTC.Video.RetransmittedBitrateSentInKbps"));
1143 EXPECT_EQ(1,
1144 metrics::NumEvents(
1145 "WebRTC.Video.RetransmittedBitrateSentInKbps",
1146 static_cast<int>((counters.retransmitted.TotalBytes() * 2 * 8) /
1147 metrics::kMinRunTimeInSeconds / 1000)));
1148
1149 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.RtxBitrateSentInKbps"));
1150 EXPECT_EQ(
1151 1, metrics::NumEvents(
1152 "WebRTC.Video.RtxBitrateSentInKbps",
1153 static_cast<int>((rtx_counters.transmitted.TotalBytes() * 2 * 8) /
1154 metrics::kMinRunTimeInSeconds / 1000)));
1155
1156 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.FecBitrateSentInKbps"));
1157 EXPECT_EQ(1, metrics::NumEvents(
1158 "WebRTC.Video.FecBitrateSentInKbps",
1159 static_cast<int>((counters.fec.TotalBytes() * 2 * 8) /
1160 metrics::kMinRunTimeInSeconds / 1000)));
1161}
1162
Erik Språng22c2b482016-03-01 08:40:421163TEST_F(SendStatisticsProxyTest, ResetsRtpCountersOnContentChange) {
1164 StreamDataCountersCallback* proxy =
1165 static_cast<StreamDataCountersCallback*>(statistics_proxy_.get());
1166 StreamDataCounters counters;
1167 StreamDataCounters rtx_counters;
1168 counters.first_packet_time_ms = fake_clock_.TimeInMilliseconds();
1169 proxy->DataCountersUpdated(counters, kFirstSsrc);
1170 proxy->DataCountersUpdated(counters, kSecondSsrc);
1171 proxy->DataCountersUpdated(rtx_counters, kFirstRtxSsrc);
1172 proxy->DataCountersUpdated(rtx_counters, kSecondRtxSsrc);
1173
asaperssona6a699a2016-11-25 11:52:461174 counters.transmitted.header_bytes = 5000;
Erik Språng22c2b482016-03-01 08:40:421175 counters.transmitted.packets = 20;
asaperssona6a699a2016-11-25 11:52:461176 counters.transmitted.padding_bytes = 10000;
1177 counters.transmitted.payload_bytes = 20000;
Erik Språng22c2b482016-03-01 08:40:421178
asaperssona6a699a2016-11-25 11:52:461179 counters.retransmitted.header_bytes = 400;
Erik Språng22c2b482016-03-01 08:40:421180 counters.retransmitted.packets = 2;
asaperssona6a699a2016-11-25 11:52:461181 counters.retransmitted.padding_bytes = 1000;
1182 counters.retransmitted.payload_bytes = 2000;
Erik Språng22c2b482016-03-01 08:40:421183
1184 counters.fec = counters.retransmitted;
1185
1186 rtx_counters.transmitted = counters.transmitted;
1187
1188 fake_clock_.AdvanceTimeMilliseconds(1000 * metrics::kMinRunTimeInSeconds);
1189 proxy->DataCountersUpdated(counters, kFirstSsrc);
1190 proxy->DataCountersUpdated(counters, kSecondSsrc);
1191 proxy->DataCountersUpdated(rtx_counters, kFirstRtxSsrc);
1192 proxy->DataCountersUpdated(rtx_counters, kSecondRtxSsrc);
1193
1194 // Changing content type causes histograms to be reported.
Pera48ddb72016-09-29 09:48:501195 VideoEncoderConfig config;
1196 config.content_type = VideoEncoderConfig::ContentType::kScreen;
1197 statistics_proxy_->OnEncoderReconfigured(config, 50);
Erik Språng22c2b482016-03-01 08:40:421198
asapersson01d70a32016-05-20 13:29:461199 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.BitrateSentInKbps"));
1200 EXPECT_EQ(1,
1201 metrics::NumEvents(
1202 "WebRTC.Video.BitrateSentInKbps",
1203 static_cast<int>((counters.transmitted.TotalBytes() * 4 * 8) /
1204 metrics::kMinRunTimeInSeconds / 1000)));
1205
1206 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.MediaBitrateSentInKbps"));
1207 EXPECT_EQ(1, metrics::NumEvents(
1208 "WebRTC.Video.MediaBitrateSentInKbps",
1209 static_cast<int>((counters.MediaPayloadBytes() * 2 * 8) /
1210 metrics::kMinRunTimeInSeconds / 1000)));
1211
1212 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.PaddingBitrateSentInKbps"));
1213 EXPECT_EQ(1,
1214 metrics::NumEvents(
1215 "WebRTC.Video.PaddingBitrateSentInKbps",
1216 static_cast<int>((counters.transmitted.padding_bytes * 4 * 8) /
1217 metrics::kMinRunTimeInSeconds / 1000)));
Erik Språng22c2b482016-03-01 08:40:421218
1219 EXPECT_EQ(1,
asapersson01d70a32016-05-20 13:29:461220 metrics::NumSamples("WebRTC.Video.RetransmittedBitrateSentInKbps"));
Erik Språng22c2b482016-03-01 08:40:421221 EXPECT_EQ(1,
asapersson01d70a32016-05-20 13:29:461222 metrics::NumEvents(
1223 "WebRTC.Video.RetransmittedBitrateSentInKbps",
1224 static_cast<int>((counters.retransmitted.TotalBytes() * 2 * 8) /
1225 metrics::kMinRunTimeInSeconds / 1000)));
Erik Språng22c2b482016-03-01 08:40:421226
asapersson01d70a32016-05-20 13:29:461227 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.RtxBitrateSentInKbps"));
Erik Språng22c2b482016-03-01 08:40:421228 EXPECT_EQ(
asapersson01d70a32016-05-20 13:29:461229 1, metrics::NumEvents(
1230 "WebRTC.Video.RtxBitrateSentInKbps",
1231 static_cast<int>((rtx_counters.transmitted.TotalBytes() * 2 * 8) /
1232 metrics::kMinRunTimeInSeconds / 1000)));
Erik Språng22c2b482016-03-01 08:40:421233
asapersson01d70a32016-05-20 13:29:461234 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.FecBitrateSentInKbps"));
1235 EXPECT_EQ(1, metrics::NumEvents(
1236 "WebRTC.Video.FecBitrateSentInKbps",
asaperssona6a699a2016-11-25 11:52:461237 static_cast<int>((counters.fec.TotalBytes() * 2 * 8) /
asapersson01d70a32016-05-20 13:29:461238 metrics::kMinRunTimeInSeconds / 1000)));
Erik Språng22c2b482016-03-01 08:40:421239
1240 // New start time but same counter values.
1241 proxy->DataCountersUpdated(counters, kFirstSsrc);
1242 proxy->DataCountersUpdated(counters, kSecondSsrc);
1243 proxy->DataCountersUpdated(rtx_counters, kFirstRtxSsrc);
1244 proxy->DataCountersUpdated(rtx_counters, kSecondRtxSsrc);
1245
1246 // Double counter values, this should result in the same counts as before but
1247 // with new histogram names.
1248 StreamDataCounters new_counters = counters;
1249 new_counters.Add(counters);
1250 StreamDataCounters new_rtx_counters = rtx_counters;
1251 new_rtx_counters.Add(rtx_counters);
1252
1253 fake_clock_.AdvanceTimeMilliseconds(1000 * metrics::kMinRunTimeInSeconds);
1254 proxy->DataCountersUpdated(new_counters, kFirstSsrc);
1255 proxy->DataCountersUpdated(new_counters, kSecondSsrc);
1256 proxy->DataCountersUpdated(new_rtx_counters, kFirstRtxSsrc);
1257 proxy->DataCountersUpdated(new_rtx_counters, kSecondRtxSsrc);
1258
1259 SetUp(); // Reset stats proxy also causes histograms to be reported.
1260
asapersson01d70a32016-05-20 13:29:461261 EXPECT_EQ(1,
1262 metrics::NumSamples("WebRTC.Video.Screenshare.BitrateSentInKbps"));
1263 EXPECT_EQ(1,
1264 metrics::NumEvents(
1265 "WebRTC.Video.Screenshare.BitrateSentInKbps",
1266 static_cast<int>((counters.transmitted.TotalBytes() * 4 * 8) /
1267 metrics::kMinRunTimeInSeconds / 1000)));
Erik Språng22c2b482016-03-01 08:40:421268
asapersson01d70a32016-05-20 13:29:461269 EXPECT_EQ(1, metrics::NumSamples(
Erik Språng22c2b482016-03-01 08:40:421270 "WebRTC.Video.Screenshare.MediaBitrateSentInKbps"));
asapersson01d70a32016-05-20 13:29:461271 EXPECT_EQ(1, metrics::NumEvents(
1272 "WebRTC.Video.Screenshare.MediaBitrateSentInKbps",
1273 static_cast<int>((counters.MediaPayloadBytes() * 2 * 8) /
1274 metrics::kMinRunTimeInSeconds / 1000)));
Erik Språng22c2b482016-03-01 08:40:421275
asapersson01d70a32016-05-20 13:29:461276 EXPECT_EQ(1, metrics::NumSamples(
Erik Språng22c2b482016-03-01 08:40:421277 "WebRTC.Video.Screenshare.PaddingBitrateSentInKbps"));
asapersson01d70a32016-05-20 13:29:461278 EXPECT_EQ(1,
1279 metrics::NumEvents(
1280 "WebRTC.Video.Screenshare.PaddingBitrateSentInKbps",
1281 static_cast<int>((counters.transmitted.padding_bytes * 4 * 8) /
1282 metrics::kMinRunTimeInSeconds / 1000)));
Erik Språng22c2b482016-03-01 08:40:421283
asapersson01d70a32016-05-20 13:29:461284 EXPECT_EQ(1, metrics::NumSamples(
Erik Språng22c2b482016-03-01 08:40:421285 "WebRTC.Video.Screenshare.RetransmittedBitrateSentInKbps"));
asapersson01d70a32016-05-20 13:29:461286 EXPECT_EQ(1,
1287 metrics::NumEvents(
1288 "WebRTC.Video.Screenshare.RetransmittedBitrateSentInKbps",
1289 static_cast<int>((counters.retransmitted.TotalBytes() * 2 * 8) /
1290 metrics::kMinRunTimeInSeconds / 1000)));
Erik Språng22c2b482016-03-01 08:40:421291
asapersson01d70a32016-05-20 13:29:461292 EXPECT_EQ(
1293 1, metrics::NumSamples("WebRTC.Video.Screenshare.RtxBitrateSentInKbps"));
1294 EXPECT_EQ(
1295 1, metrics::NumEvents(
1296 "WebRTC.Video.Screenshare.RtxBitrateSentInKbps",
1297 static_cast<int>((rtx_counters.transmitted.TotalBytes() * 2 * 8) /
1298 metrics::kMinRunTimeInSeconds / 1000)));
Erik Språng22c2b482016-03-01 08:40:421299
asapersson01d70a32016-05-20 13:29:461300 EXPECT_EQ(
1301 1, metrics::NumSamples("WebRTC.Video.Screenshare.FecBitrateSentInKbps"));
1302 EXPECT_EQ(1, metrics::NumEvents(
1303 "WebRTC.Video.Screenshare.FecBitrateSentInKbps",
asaperssona6a699a2016-11-25 11:52:461304 static_cast<int>((counters.fec.TotalBytes() * 2 * 8) /
asapersson01d70a32016-05-20 13:29:461305 metrics::kMinRunTimeInSeconds / 1000)));
Erik Språng22c2b482016-03-01 08:40:421306}
1307
sprang@webrtc.orgccd42842014-01-07 09:54:341308} // namespace webrtc