blob: 2767d7f75f568404e2b04045df08773609c9058c [file] [log] [blame]
pbos@webrtc.org744fbc72013-09-10 09:26:25 +00001/*
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 */
pbos@webrtc.org744fbc72013-09-10 09:26:25 +000010
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "call/rampup_tests.h"
stefanff483612015-12-21 03:14:00 -080012
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020013#include "rtc_base/checks.h"
14#include "rtc_base/logging.h"
15#include "rtc_base/platform_thread.h"
Jonas Olsson0a713b62018-04-04 15:49:32 +020016#include "rtc_base/stringencode.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "test/encoder_settings.h"
18#include "test/gtest.h"
19#include "test/testsupport/perf_test.h"
pbos@webrtc.org744fbc72013-09-10 09:26:25 +000020
21namespace webrtc {
pbos@webrtc.org29023282013-09-11 10:14:56 +000022namespace {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000023
Stefan Holmer723dff12015-10-05 14:59:41 +020024static const int64_t kPollIntervalMs = 20;
philipel5ef2bc12017-02-21 07:28:31 -080025static const int kExpectedHighVideoBitrateBps = 80000;
stefandb752f92016-12-05 08:23:40 -080026static const int kExpectedHighAudioBitrateBps = 30000;
27static const int kLowBandwidthLimitBps = 20000;
Sebastian Jansson12fb1702018-02-23 11:34:18 +010028// Set target detected bitrate to slightly larger than the target bitrate to
29// avoid flakiness.
30static const int kLowBitrateMarginBps = 2000;
pbos@webrtc.org29023282013-09-11 10:14:56 +000031
stefanff483612015-12-21 03:14:00 -080032std::vector<uint32_t> GenerateSsrcs(size_t num_streams, uint32_t ssrc_offset) {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000033 std::vector<uint32_t> ssrcs;
34 for (size_t i = 0; i != num_streams; ++i)
35 ssrcs.push_back(static_cast<uint32_t>(ssrc_offset + i));
36 return ssrcs;
37}
mflodman@webrtc.orgeb16b812014-06-16 08:57:39 +000038} // namespace
henrik.lundin@webrtc.org845862f2014-03-06 07:19:28 +000039
stefanff483612015-12-21 03:14:00 -080040RampUpTester::RampUpTester(size_t num_video_streams,
41 size_t num_audio_streams,
philipel5ef2bc12017-02-21 07:28:31 -080042 size_t num_flexfec_streams,
stefan4fbd1452015-09-28 03:57:14 -070043 unsigned int start_bitrate_bps,
stefan5a2c5062017-01-27 06:43:18 -080044 int64_t min_run_time_ms,
stefan4fbd1452015-09-28 03:57:14 -070045 const std::string& extension_type,
46 bool rtx,
stefan5a2c5062017-01-27 06:43:18 -080047 bool red,
48 bool report_perf_stats)
stefan4fbd1452015-09-28 03:57:14 -070049 : EndToEndTest(test::CallTest::kLongTimeoutMs),
tommi0f8b4032017-02-22 11:22:05 -080050 stop_event_(false, false),
stefan4fbd1452015-09-28 03:57:14 -070051 clock_(Clock::GetRealTimeClock()),
stefanff483612015-12-21 03:14:00 -080052 num_video_streams_(num_video_streams),
53 num_audio_streams_(num_audio_streams),
philipel5ef2bc12017-02-21 07:28:31 -080054 num_flexfec_streams_(num_flexfec_streams),
stefan4fbd1452015-09-28 03:57:14 -070055 rtx_(rtx),
56 red_(red),
stefan45b5fe52017-03-09 06:27:02 -080057 report_perf_stats_(report_perf_stats),
mflodman86cc6ff2016-07-26 04:44:06 -070058 sender_call_(nullptr),
stefan4fbd1452015-09-28 03:57:14 -070059 send_stream_(nullptr),
sprang4847ae62017-06-27 07:06:52 -070060 send_transport_(nullptr),
stefan4fbd1452015-09-28 03:57:14 -070061 start_bitrate_bps_(start_bitrate_bps),
stefan5a2c5062017-01-27 06:43:18 -080062 min_run_time_ms_(min_run_time_ms),
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000063 expected_bitrate_bps_(0),
Erik Språngf3a7c9d2015-10-05 14:03:22 +020064 test_start_ms_(-1),
stefan4fbd1452015-09-28 03:57:14 -070065 ramp_up_finished_ms_(-1),
66 extension_type_(extension_type),
stefanff483612015-12-21 03:14:00 -080067 video_ssrcs_(GenerateSsrcs(num_video_streams_, 100)),
68 video_rtx_ssrcs_(GenerateSsrcs(num_video_streams_, 200)),
69 audio_ssrcs_(GenerateSsrcs(num_audio_streams_, 300)),
Peter Boström8c38e8b2015-11-26 17:45:47 +010070 poller_thread_(&BitrateStatsPollingThread,
71 this,
mflodman86cc6ff2016-07-26 04:44:06 -070072 "BitrateStatsPollingThread") {
philipel5ef2bc12017-02-21 07:28:31 -080073 if (red_)
74 EXPECT_EQ(0u, num_flexfec_streams_);
Stefan Holmerff2a6352016-01-14 10:00:21 +010075 EXPECT_LE(num_audio_streams_, 1u);
stefan4fbd1452015-09-28 03:57:14 -070076}
77
Yves Gerey665174f2018-06-19 15:03:05 +020078RampUpTester::~RampUpTester() {}
stefan4fbd1452015-09-28 03:57:14 -070079
80Call::Config RampUpTester::GetSenderCallConfig() {
skvlad11a9cbf2016-10-07 11:53:05 -070081 Call::Config call_config(&event_log_);
stefan4fbd1452015-09-28 03:57:14 -070082 if (start_bitrate_bps_ != 0) {
83 call_config.bitrate_config.start_bitrate_bps = start_bitrate_bps_;
84 }
85 call_config.bitrate_config.min_bitrate_bps = 10000;
86 return call_config;
87}
88
stefanff483612015-12-21 03:14:00 -080089void RampUpTester::OnVideoStreamsCreated(
stefan4fbd1452015-09-28 03:57:14 -070090 VideoSendStream* send_stream,
91 const std::vector<VideoReceiveStream*>& receive_streams) {
92 send_stream_ = send_stream;
93}
94
eladalon413ee9a2017-08-22 04:02:52 -070095test::PacketTransport* RampUpTester::CreateSendTransport(
96 test::SingleThreadedTaskQueueForTesting* task_queue,
97 Call* sender_call) {
minyue20c84cc2017-04-10 16:57:57 -070098 send_transport_ = new test::PacketTransport(
eladalon413ee9a2017-08-22 04:02:52 -070099 task_queue, sender_call, this, test::PacketTransport::kSender,
minyue20c84cc2017-04-10 16:57:57 -0700100 test::CallTest::payload_type_map_, forward_transport_config_);
stefane74eef12016-01-08 06:47:13 -0800101 return send_transport_;
stefanf116bd02015-10-27 08:29:42 -0700102}
103
Stefan Holmerd20e6512016-01-12 15:51:22 +0100104size_t RampUpTester::GetNumVideoStreams() const {
105 return num_video_streams_;
106}
107
Stefan Holmerff2a6352016-01-14 10:00:21 +0100108size_t RampUpTester::GetNumAudioStreams() const {
109 return num_audio_streams_;
110}
111
philipel5ef2bc12017-02-21 07:28:31 -0800112size_t RampUpTester::GetNumFlexfecStreams() const {
113 return num_flexfec_streams_;
114}
115
perkjfa10b552016-10-02 23:45:26 -0700116class RampUpTester::VideoStreamFactory
117 : public VideoEncoderConfig::VideoStreamFactoryInterface {
118 public:
119 VideoStreamFactory() {}
120
121 private:
122 std::vector<VideoStream> CreateEncoderStreams(
123 int width,
124 int height,
125 const VideoEncoderConfig& encoder_config) override {
126 std::vector<VideoStream> streams =
127 test::CreateVideoStreams(width, height, encoder_config);
128 if (encoder_config.number_of_streams == 1) {
129 streams[0].target_bitrate_bps = streams[0].max_bitrate_bps = 2000000;
130 }
131 return streams;
132 }
133};
134
stefanff483612015-12-21 03:14:00 -0800135void RampUpTester::ModifyVideoConfigs(
stefan4fbd1452015-09-28 03:57:14 -0700136 VideoSendStream::Config* send_config,
137 std::vector<VideoReceiveStream::Config>* receive_configs,
138 VideoEncoderConfig* encoder_config) {
139 send_config->suspend_below_min_bitrate = true;
perkjfa10b552016-10-02 23:45:26 -0700140 encoder_config->number_of_streams = num_video_streams_;
141 encoder_config->max_bitrate_bps = 2000000;
142 encoder_config->video_stream_factory =
143 new rtc::RefCountedObject<RampUpTester::VideoStreamFactory>();
stefanff483612015-12-21 03:14:00 -0800144 if (num_video_streams_ == 1) {
stefan4fbd1452015-09-28 03:57:14 -0700145 // For single stream rampup until 1mbps
146 expected_bitrate_bps_ = kSingleStreamTargetBps;
147 } else {
148 // For multi stream rampup until all streams are being sent. That means
perkjfa10b552016-10-02 23:45:26 -0700149 // enough bitrate to send all the target streams plus the min bitrate of
stefan4fbd1452015-09-28 03:57:14 -0700150 // the last one.
perkjfa10b552016-10-02 23:45:26 -0700151 std::vector<VideoStream> streams = test::CreateVideoStreams(
152 test::CallTest::kDefaultWidth, test::CallTest::kDefaultHeight,
153 *encoder_config);
154 expected_bitrate_bps_ = streams.back().min_bitrate_bps;
155 for (size_t i = 0; i < streams.size() - 1; ++i) {
156 expected_bitrate_bps_ += streams[i].target_bitrate_bps;
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000157 }
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000158 }
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000159
stefan4fbd1452015-09-28 03:57:14 -0700160 send_config->rtp.extensions.clear();
161
162 bool remb;
stefan43edf0f2015-11-20 18:05:48 -0800163 bool transport_cc;
isheriff6f8d6862016-05-26 11:24:55 -0700164 if (extension_type_ == RtpExtension::kAbsSendTimeUri) {
stefan4fbd1452015-09-28 03:57:14 -0700165 remb = true;
stefan43edf0f2015-11-20 18:05:48 -0800166 transport_cc = false;
stefan4fbd1452015-09-28 03:57:14 -0700167 send_config->rtp.extensions.push_back(
168 RtpExtension(extension_type_.c_str(), kAbsSendTimeExtensionId));
isheriff6f8d6862016-05-26 11:24:55 -0700169 } else if (extension_type_ == RtpExtension::kTransportSequenceNumberUri) {
stefan4fbd1452015-09-28 03:57:14 -0700170 remb = false;
stefan43edf0f2015-11-20 18:05:48 -0800171 transport_cc = true;
stefan4fbd1452015-09-28 03:57:14 -0700172 send_config->rtp.extensions.push_back(RtpExtension(
173 extension_type_.c_str(), kTransportSequenceNumberExtensionId));
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000174 } else {
stefan4fbd1452015-09-28 03:57:14 -0700175 remb = true;
stefan43edf0f2015-11-20 18:05:48 -0800176 transport_cc = false;
stefan4fbd1452015-09-28 03:57:14 -0700177 send_config->rtp.extensions.push_back(RtpExtension(
178 extension_type_.c_str(), kTransmissionTimeOffsetExtensionId));
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000179 }
stefan4fbd1452015-09-28 03:57:14 -0700180
181 send_config->rtp.nack.rtp_history_ms = test::CallTest::kNackRtpHistoryMs;
stefanff483612015-12-21 03:14:00 -0800182 send_config->rtp.ssrcs = video_ssrcs_;
stefan4fbd1452015-09-28 03:57:14 -0700183 if (rtx_) {
184 send_config->rtp.rtx.payload_type = test::CallTest::kSendRtxPayloadType;
stefanff483612015-12-21 03:14:00 -0800185 send_config->rtp.rtx.ssrcs = video_rtx_ssrcs_;
stefan4fbd1452015-09-28 03:57:14 -0700186 }
187 if (red_) {
brandtrb5f2c3f2016-10-04 23:28:39 -0700188 send_config->rtp.ulpfec.ulpfec_payload_type =
stefan4fbd1452015-09-28 03:57:14 -0700189 test::CallTest::kUlpfecPayloadType;
brandtrb5f2c3f2016-10-04 23:28:39 -0700190 send_config->rtp.ulpfec.red_payload_type = test::CallTest::kRedPayloadType;
brandtrfbfb5362016-11-17 04:18:37 -0800191 if (rtx_) {
192 send_config->rtp.ulpfec.red_rtx_payload_type =
193 test::CallTest::kRtxRedPayloadType;
194 }
stefan4fbd1452015-09-28 03:57:14 -0700195 }
196
197 size_t i = 0;
198 for (VideoReceiveStream::Config& recv_config : *receive_configs) {
199 recv_config.rtp.remb = remb;
stefan43edf0f2015-11-20 18:05:48 -0800200 recv_config.rtp.transport_cc = transport_cc;
stefan4fbd1452015-09-28 03:57:14 -0700201 recv_config.rtp.extensions = send_config->rtp.extensions;
202
stefanff483612015-12-21 03:14:00 -0800203 recv_config.rtp.remote_ssrc = video_ssrcs_[i];
stefan4fbd1452015-09-28 03:57:14 -0700204 recv_config.rtp.nack.rtp_history_ms = send_config->rtp.nack.rtp_history_ms;
205
206 if (red_) {
nisse3b3622f2017-09-26 02:49:21 -0700207 recv_config.rtp.red_payload_type =
brandtrb5f2c3f2016-10-04 23:28:39 -0700208 send_config->rtp.ulpfec.red_payload_type;
nisse3b3622f2017-09-26 02:49:21 -0700209 recv_config.rtp.ulpfec_payload_type =
brandtrb5f2c3f2016-10-04 23:28:39 -0700210 send_config->rtp.ulpfec.ulpfec_payload_type;
brandtrfbfb5362016-11-17 04:18:37 -0800211 if (rtx_) {
nisseca5706d2017-09-11 02:32:16 -0700212 recv_config.rtp.rtx_associated_payload_types
213 [send_config->rtp.ulpfec.red_rtx_payload_type] =
214 send_config->rtp.ulpfec.red_payload_type;
brandtrfbfb5362016-11-17 04:18:37 -0800215 }
stefan4fbd1452015-09-28 03:57:14 -0700216 }
217
218 if (rtx_) {
brandtr14742122017-01-27 04:53:07 -0800219 recv_config.rtp.rtx_ssrc = video_rtx_ssrcs_[i];
220 recv_config.rtp
nisse26e3abb2017-08-25 04:44:25 -0700221 .rtx_associated_payload_types[send_config->rtp.rtx.payload_type] =
Niels Möller259a4972018-04-05 15:36:51 +0200222 send_config->rtp.payload_type;
stefan4fbd1452015-09-28 03:57:14 -0700223 }
224 ++i;
225 }
philipel5ef2bc12017-02-21 07:28:31 -0800226
227 RTC_DCHECK_LE(num_flexfec_streams_, 1);
228 if (num_flexfec_streams_ == 1) {
229 send_config->rtp.flexfec.payload_type = test::CallTest::kFlexfecPayloadType;
230 send_config->rtp.flexfec.ssrc = test::CallTest::kFlexfecSendSsrc;
231 send_config->rtp.flexfec.protected_media_ssrcs = {video_ssrcs_[0]};
232 }
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000233}
234
Stefan Holmerff2a6352016-01-14 10:00:21 +0100235void RampUpTester::ModifyAudioConfigs(
236 AudioSendStream::Config* send_config,
237 std::vector<AudioReceiveStream::Config>* receive_configs) {
238 if (num_audio_streams_ == 0)
239 return;
240
isheriff6f8d6862016-05-26 11:24:55 -0700241 EXPECT_NE(RtpExtension::kTimestampOffsetUri, extension_type_)
Stefan Holmerff2a6352016-01-14 10:00:21 +0100242 << "Audio BWE not supported with toffset.";
philipel5ef2bc12017-02-21 07:28:31 -0800243 EXPECT_NE(RtpExtension::kAbsSendTimeUri, extension_type_)
244 << "Audio BWE not supported with abs-send-time.";
Stefan Holmerff2a6352016-01-14 10:00:21 +0100245
246 send_config->rtp.ssrc = audio_ssrcs_[0];
247 send_config->rtp.extensions.clear();
248
minyue10cbb462016-11-07 09:29:22 -0800249 send_config->min_bitrate_bps = 6000;
250 send_config->max_bitrate_bps = 60000;
mflodman86cc6ff2016-07-26 04:44:06 -0700251
Stefan Holmerff2a6352016-01-14 10:00:21 +0100252 bool transport_cc = false;
philipel5ef2bc12017-02-21 07:28:31 -0800253 if (extension_type_ == RtpExtension::kTransportSequenceNumberUri) {
Stefan Holmerff2a6352016-01-14 10:00:21 +0100254 transport_cc = true;
255 send_config->rtp.extensions.push_back(RtpExtension(
256 extension_type_.c_str(), kTransportSequenceNumberExtensionId));
257 }
258
259 for (AudioReceiveStream::Config& recv_config : *receive_configs) {
Stefan Holmerff2a6352016-01-14 10:00:21 +0100260 recv_config.rtp.transport_cc = transport_cc;
261 recv_config.rtp.extensions = send_config->rtp.extensions;
262 recv_config.rtp.remote_ssrc = send_config->rtp.ssrc;
263 }
264}
265
philipel5ef2bc12017-02-21 07:28:31 -0800266void RampUpTester::ModifyFlexfecConfigs(
267 std::vector<FlexfecReceiveStream::Config>* receive_configs) {
268 if (num_flexfec_streams_ == 0)
269 return;
270 RTC_DCHECK_EQ(1, num_flexfec_streams_);
271 (*receive_configs)[0].payload_type = test::CallTest::kFlexfecPayloadType;
272 (*receive_configs)[0].remote_ssrc = test::CallTest::kFlexfecSendSsrc;
273 (*receive_configs)[0].protected_media_ssrcs = {video_ssrcs_[0]};
274 (*receive_configs)[0].local_ssrc = video_ssrcs_[0];
275 if (extension_type_ == RtpExtension::kAbsSendTimeUri) {
276 (*receive_configs)[0].transport_cc = false;
277 (*receive_configs)[0].rtp_header_extensions.push_back(
278 RtpExtension(extension_type_.c_str(), kAbsSendTimeExtensionId));
279 } else if (extension_type_ == RtpExtension::kTransportSequenceNumberUri) {
280 (*receive_configs)[0].transport_cc = true;
281 (*receive_configs)[0].rtp_header_extensions.push_back(RtpExtension(
282 extension_type_.c_str(), kTransportSequenceNumberExtensionId));
283 }
284}
285
stefan4fbd1452015-09-28 03:57:14 -0700286void RampUpTester::OnCallsCreated(Call* sender_call, Call* receiver_call) {
287 sender_call_ = sender_call;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000288}
289
tommi0f8b4032017-02-22 11:22:05 -0800290void RampUpTester::BitrateStatsPollingThread(void* obj) {
291 static_cast<RampUpTester*>(obj)->PollStats();
pbos@webrtc.org32452b22014-10-22 12:15:24 +0000292}
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000293
tommi0f8b4032017-02-22 11:22:05 -0800294void RampUpTester::PollStats() {
295 do {
296 if (sender_call_) {
297 Call::Stats stats = sender_call_->GetStats();
stefan4fbd1452015-09-28 03:57:14 -0700298
tommi0f8b4032017-02-22 11:22:05 -0800299 EXPECT_GE(stats.send_bandwidth_bps, start_bitrate_bps_);
300 EXPECT_GE(expected_bitrate_bps_, 0);
301 if (stats.send_bandwidth_bps >= expected_bitrate_bps_ &&
302 (min_run_time_ms_ == -1 ||
303 clock_->TimeInMilliseconds() - test_start_ms_ >= min_run_time_ms_)) {
304 ramp_up_finished_ms_ = clock_->TimeInMilliseconds();
305 observation_complete_.Set();
306 }
stefan4fbd1452015-09-28 03:57:14 -0700307 }
tommi0f8b4032017-02-22 11:22:05 -0800308 } while (!stop_event_.Wait(kPollIntervalMs));
Erik Språng468e62a2015-07-06 10:50:47 +0200309}
310
stefan4fbd1452015-09-28 03:57:14 -0700311void RampUpTester::ReportResult(const std::string& measurement,
312 size_t value,
313 const std::string& units) const {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000314 webrtc::test::PrintResult(
315 measurement, "",
stefanff483612015-12-21 03:14:00 -0800316 ::testing::UnitTest::GetInstance()->current_test_info()->name(), value,
317 units, false);
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000318}
319
stefan092508a2015-09-29 02:26:42 -0700320void RampUpTester::AccumulateStats(const VideoSendStream::StreamStats& stream,
321 size_t* total_packets_sent,
322 size_t* total_sent,
323 size_t* padding_sent,
324 size_t* media_sent) const {
stefan4fbd1452015-09-28 03:57:14 -0700325 *total_packets_sent += stream.rtp_stats.transmitted.packets +
326 stream.rtp_stats.retransmitted.packets +
327 stream.rtp_stats.fec.packets;
328 *total_sent += stream.rtp_stats.transmitted.TotalBytes() +
329 stream.rtp_stats.retransmitted.TotalBytes() +
330 stream.rtp_stats.fec.TotalBytes();
331 *padding_sent += stream.rtp_stats.transmitted.padding_bytes +
332 stream.rtp_stats.retransmitted.padding_bytes +
333 stream.rtp_stats.fec.padding_bytes;
334 *media_sent += stream.rtp_stats.MediaPayloadBytes();
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000335}
336
stefan4fbd1452015-09-28 03:57:14 -0700337void RampUpTester::TriggerTestDone() {
Erik Språngf3a7c9d2015-10-05 14:03:22 +0200338 RTC_DCHECK_GE(test_start_ms_, 0);
339
Stefan Holmerff2a6352016-01-14 10:00:21 +0100340 // TODO(holmer): Add audio send stats here too when those APIs are available.
mflodman86cc6ff2016-07-26 04:44:06 -0700341 if (!send_stream_)
342 return;
343
stefan4fbd1452015-09-28 03:57:14 -0700344 VideoSendStream::Stats send_stats = send_stream_->GetStats();
345
346 size_t total_packets_sent = 0;
347 size_t total_sent = 0;
348 size_t padding_sent = 0;
349 size_t media_sent = 0;
stefanff483612015-12-21 03:14:00 -0800350 for (uint32_t ssrc : video_ssrcs_) {
stefan092508a2015-09-29 02:26:42 -0700351 AccumulateStats(send_stats.substreams[ssrc], &total_packets_sent,
352 &total_sent, &padding_sent, &media_sent);
stefan4fbd1452015-09-28 03:57:14 -0700353 }
354
355 size_t rtx_total_packets_sent = 0;
356 size_t rtx_total_sent = 0;
357 size_t rtx_padding_sent = 0;
358 size_t rtx_media_sent = 0;
stefanff483612015-12-21 03:14:00 -0800359 for (uint32_t rtx_ssrc : video_rtx_ssrcs_) {
stefan092508a2015-09-29 02:26:42 -0700360 AccumulateStats(send_stats.substreams[rtx_ssrc], &rtx_total_packets_sent,
361 &rtx_total_sent, &rtx_padding_sent, &rtx_media_sent);
stefan4fbd1452015-09-28 03:57:14 -0700362 }
363
stefan5a2c5062017-01-27 06:43:18 -0800364 if (report_perf_stats_) {
stefan5a2c5062017-01-27 06:43:18 -0800365 ReportResult("ramp-up-media-sent", media_sent, "bytes");
366 ReportResult("ramp-up-padding-sent", padding_sent, "bytes");
stefan5a2c5062017-01-27 06:43:18 -0800367 ReportResult("ramp-up-rtx-media-sent", rtx_media_sent, "bytes");
368 ReportResult("ramp-up-rtx-padding-sent", rtx_padding_sent, "bytes");
369 if (ramp_up_finished_ms_ >= 0) {
370 ReportResult("ramp-up-time", ramp_up_finished_ms_ - test_start_ms_,
371 "milliseconds");
372 }
373 ReportResult("ramp-up-average-network-latency",
374 send_transport_->GetAverageDelayMs(), "milliseconds");
stefan4fbd1452015-09-28 03:57:14 -0700375 }
376}
377
378void RampUpTester::PerformTest() {
Erik Språngf3a7c9d2015-10-05 14:03:22 +0200379 test_start_ms_ = clock_->TimeInMilliseconds();
Peter Boström8c38e8b2015-11-26 17:45:47 +0100380 poller_thread_.Start();
Peter Boström5811a392015-12-10 13:02:50 +0100381 EXPECT_TRUE(Wait()) << "Timed out while waiting for ramp-up to complete.";
stefan4fbd1452015-09-28 03:57:14 -0700382 TriggerTestDone();
tommi0f8b4032017-02-22 11:22:05 -0800383 stop_event_.Set();
Peter Boström8c38e8b2015-11-26 17:45:47 +0100384 poller_thread_.Stop();
stefan4fbd1452015-09-28 03:57:14 -0700385}
386
Stefan Holmerff2a6352016-01-14 10:00:21 +0100387RampUpDownUpTester::RampUpDownUpTester(size_t num_video_streams,
388 size_t num_audio_streams,
philipel5ef2bc12017-02-21 07:28:31 -0800389 size_t num_flexfec_streams,
stefan4fbd1452015-09-28 03:57:14 -0700390 unsigned int start_bitrate_bps,
391 const std::string& extension_type,
392 bool rtx,
philipel5ef2bc12017-02-21 07:28:31 -0800393 bool red,
stefan45b5fe52017-03-09 06:27:02 -0800394 const std::vector<int>& loss_rates,
395 bool report_perf_stats)
Stefan Holmerff2a6352016-01-14 10:00:21 +0100396 : RampUpTester(num_video_streams,
397 num_audio_streams,
philipel5ef2bc12017-02-21 07:28:31 -0800398 num_flexfec_streams,
Stefan Holmerff2a6352016-01-14 10:00:21 +0100399 start_bitrate_bps,
stefan5a2c5062017-01-27 06:43:18 -0800400 0,
Stefan Holmerff2a6352016-01-14 10:00:21 +0100401 extension_type,
402 rtx,
stefan5a2c5062017-01-27 06:43:18 -0800403 red,
stefan45b5fe52017-03-09 06:27:02 -0800404 report_perf_stats),
stefan76d9c9c2017-04-01 06:51:09 -0700405 link_rates_({4 * GetExpectedHighBitrate() / (3 * 1000),
406 kLowBandwidthLimitBps / 1000,
407 4 * GetExpectedHighBitrate() / (3 * 1000), 0}),
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000408 test_state_(kFirstRampup),
philipel5ef2bc12017-02-21 07:28:31 -0800409 next_state_(kTransitionToNextState),
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000410 state_start_ms_(clock_->TimeInMilliseconds()),
stefan4fbd1452015-09-28 03:57:14 -0700411 interval_start_ms_(clock_->TimeInMilliseconds()),
philipel5ef2bc12017-02-21 07:28:31 -0800412 sent_bytes_(0),
413 loss_rates_(loss_rates) {
414 forward_transport_config_.link_capacity_kbps = link_rates_[test_state_];
415 forward_transport_config_.queue_delay_ms = 100;
416 forward_transport_config_.loss_percent = loss_rates_[test_state_];
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000417}
418
stefan4fbd1452015-09-28 03:57:14 -0700419RampUpDownUpTester::~RampUpDownUpTester() {}
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000420
tommi0f8b4032017-02-22 11:22:05 -0800421void RampUpDownUpTester::PollStats() {
422 do {
Alex Narest78609d52017-10-20 10:37:47 +0200423 int transmit_bitrate_bps = 0;
424 bool suspended = false;
425 if (num_video_streams_ > 0) {
tommi0f8b4032017-02-22 11:22:05 -0800426 webrtc::VideoSendStream::Stats stats = send_stream_->GetStats();
tommi0f8b4032017-02-22 11:22:05 -0800427 for (auto it : stats.substreams) {
428 transmit_bitrate_bps += it.second.total_bitrate_bps;
429 }
Alex Narest78609d52017-10-20 10:37:47 +0200430 suspended = stats.suspended;
431 }
432 if (num_audio_streams_ > 0 && sender_call_ != nullptr) {
tommi0f8b4032017-02-22 11:22:05 -0800433 // An audio send stream doesn't have bitrate stats, so the call send BW is
434 // currently used instead.
Alex Narest78609d52017-10-20 10:37:47 +0200435 transmit_bitrate_bps = sender_call_->GetStats().send_bandwidth_bps;
mflodman@webrtc.orgeb16b812014-06-16 08:57:39 +0000436 }
Alex Narest78609d52017-10-20 10:37:47 +0200437 EvolveTestState(transmit_bitrate_bps, suspended);
tommi0f8b4032017-02-22 11:22:05 -0800438 } while (!stop_event_.Wait(kPollIntervalMs));
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000439}
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000440
stefan4fbd1452015-09-28 03:57:14 -0700441Call::Config RampUpDownUpTester::GetReceiverCallConfig() {
skvlad11a9cbf2016-10-07 11:53:05 -0700442 Call::Config config(&event_log_);
stefan4fbd1452015-09-28 03:57:14 -0700443 config.bitrate_config.min_bitrate_bps = 10000;
444 return config;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000445}
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000446
stefan4fbd1452015-09-28 03:57:14 -0700447std::string RampUpDownUpTester::GetModifierString() const {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000448 std::string str("_");
stefanff483612015-12-21 03:14:00 -0800449 if (num_video_streams_ > 0) {
Jonas Olsson0a713b62018-04-04 15:49:32 +0200450 str += rtc::ToString(num_video_streams_);
stefanff483612015-12-21 03:14:00 -0800451 str += "stream";
452 str += (num_video_streams_ > 1 ? "s" : "");
453 str += "_";
454 }
455 if (num_audio_streams_ > 0) {
Jonas Olsson0a713b62018-04-04 15:49:32 +0200456 str += rtc::ToString(num_audio_streams_);
stefanff483612015-12-21 03:14:00 -0800457 str += "stream";
458 str += (num_audio_streams_ > 1 ? "s" : "");
459 str += "_";
460 }
stefan4fbd1452015-09-28 03:57:14 -0700461 str += (rtx_ ? "" : "no");
Edward Lemurdd3987f2018-01-04 19:44:54 +0100462 str += "rtx_";
463 str += (red_ ? "" : "no");
464 str += "red";
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000465 return str;
466}
andresp@webrtc.orgc1480792014-03-20 03:23:55 +0000467
stefandb752f92016-12-05 08:23:40 -0800468int RampUpDownUpTester::GetExpectedHighBitrate() const {
stefan38d8b3c2017-01-09 04:19:24 -0800469 int expected_bitrate_bps = 0;
470 if (num_audio_streams_ > 0)
471 expected_bitrate_bps += kExpectedHighAudioBitrateBps;
472 if (num_video_streams_ > 0)
473 expected_bitrate_bps += kExpectedHighVideoBitrateBps;
474 return expected_bitrate_bps;
475}
476
philipel5ef2bc12017-02-21 07:28:31 -0800477size_t RampUpDownUpTester::GetFecBytes() const {
478 size_t flex_fec_bytes = 0;
479 if (num_flexfec_streams_ > 0) {
480 webrtc::VideoSendStream::Stats stats = send_stream_->GetStats();
481 for (const auto& kv : stats.substreams)
482 flex_fec_bytes += kv.second.rtp_stats.fec.TotalBytes();
483 }
484 return flex_fec_bytes;
485}
486
487bool RampUpDownUpTester::ExpectingFec() const {
488 return num_flexfec_streams_ > 0 && forward_transport_config_.loss_percent > 0;
489}
490
stefan4fbd1452015-09-28 03:57:14 -0700491void RampUpDownUpTester::EvolveTestState(int bitrate_bps, bool suspended) {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000492 int64_t now = clock_->TimeInMilliseconds();
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000493 switch (test_state_) {
philipel5ef2bc12017-02-21 07:28:31 -0800494 case kFirstRampup:
stefan4fbd1452015-09-28 03:57:14 -0700495 EXPECT_FALSE(suspended);
stefandb752f92016-12-05 08:23:40 -0800496 if (bitrate_bps >= GetExpectedHighBitrate()) {
stefan45b5fe52017-03-09 06:27:02 -0800497 if (report_perf_stats_) {
498 webrtc::test::PrintResult("ramp_up_down_up", GetModifierString(),
499 "first_rampup", now - state_start_ms_, "ms",
500 false);
501 }
philipel5ef2bc12017-02-21 07:28:31 -0800502 // Apply loss during the transition between states if FEC is enabled.
503 forward_transport_config_.loss_percent = loss_rates_[test_state_];
504 test_state_ = kTransitionToNextState;
505 next_state_ = kLowRate;
andresp@webrtc.orgc1480792014-03-20 03:23:55 +0000506 }
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000507 break;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000508 case kLowRate: {
mflodman86cc6ff2016-07-26 04:44:06 -0700509 // Audio streams are never suspended.
510 bool check_suspend_state = num_video_streams_ > 0;
Sebastian Jansson12fb1702018-02-23 11:34:18 +0100511 if (bitrate_bps < kLowBandwidthLimitBps + kLowBitrateMarginBps &&
mflodman86cc6ff2016-07-26 04:44:06 -0700512 suspended == check_suspend_state) {
stefan45b5fe52017-03-09 06:27:02 -0800513 if (report_perf_stats_) {
514 webrtc::test::PrintResult("ramp_up_down_up", GetModifierString(),
515 "rampdown", now - state_start_ms_, "ms",
516 false);
517 }
philipel5ef2bc12017-02-21 07:28:31 -0800518 // Apply loss during the transition between states if FEC is enabled.
519 forward_transport_config_.loss_percent = loss_rates_[test_state_];
520 test_state_ = kTransitionToNextState;
521 next_state_ = kSecondRampup;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000522 }
523 break;
524 }
philipel5ef2bc12017-02-21 07:28:31 -0800525 case kSecondRampup:
stefandb752f92016-12-05 08:23:40 -0800526 if (bitrate_bps >= GetExpectedHighBitrate() && !suspended) {
stefan45b5fe52017-03-09 06:27:02 -0800527 if (report_perf_stats_) {
528 webrtc::test::PrintResult("ramp_up_down_up", GetModifierString(),
529 "second_rampup", now - state_start_ms_,
530 "ms", false);
531 ReportResult("ramp-up-down-up-average-network-latency",
532 send_transport_->GetAverageDelayMs(), "milliseconds");
533 }
philipel5ef2bc12017-02-21 07:28:31 -0800534 // Apply loss during the transition between states if FEC is enabled.
535 forward_transport_config_.loss_percent = loss_rates_[test_state_];
536 test_state_ = kTransitionToNextState;
537 next_state_ = kTestEnd;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000538 }
539 break;
philipel5ef2bc12017-02-21 07:28:31 -0800540 case kTestEnd:
541 observation_complete_.Set();
542 break;
543 case kTransitionToNextState:
544 if (!ExpectingFec() || GetFecBytes() > 0) {
545 test_state_ = next_state_;
546 forward_transport_config_.link_capacity_kbps = link_rates_[test_state_];
547 // No loss while ramping up and down as it may affect the BWE
548 // negatively, making the test flaky.
549 forward_transport_config_.loss_percent = 0;
550 state_start_ms_ = now;
551 interval_start_ms_ = now;
552 sent_bytes_ = 0;
553 send_transport_->SetConfig(forward_transport_config_);
554 }
555 break;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000556 }
557}
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +0000558
stefan4fbd1452015-09-28 03:57:14 -0700559class RampUpTest : public test::CallTest {
Erik Språng6b8d3552015-09-24 15:06:57 +0200560 public:
stefan4fbd1452015-09-28 03:57:14 -0700561 RampUpTest() {}
Erik Språng6b8d3552015-09-24 15:06:57 +0200562
stefan4fbd1452015-09-28 03:57:14 -0700563 virtual ~RampUpTest() {
stefanff483612015-12-21 03:14:00 -0800564 EXPECT_EQ(nullptr, video_send_stream_);
565 EXPECT_TRUE(video_receive_streams_.empty());
Erik Språng6b8d3552015-09-24 15:06:57 +0200566 }
Erik Språng6b8d3552015-09-24 15:06:57 +0200567};
568
Stefan Holmerff2a6352016-01-14 10:00:21 +0100569static const uint32_t kStartBitrateBps = 60000;
570
stefan38d8b3c2017-01-09 04:19:24 -0800571TEST_F(RampUpTest, UpDownUpAbsSendTimeSimulcastRedRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800572 std::vector<int> loss_rates = {0, 0, 0, 0};
573 RampUpDownUpTester test(3, 0, 0, kStartBitrateBps,
stefan45b5fe52017-03-09 06:27:02 -0800574 RtpExtension::kAbsSendTimeUri, true, true, loss_rates,
575 true);
stefane74eef12016-01-08 06:47:13 -0800576 RunBaseTest(&test);
Shao Changbine62202f2015-04-21 20:24:50 +0800577}
Stefan Holmerff2a6352016-01-14 10:00:21 +0100578
Taylor Brandstetterba6b5032018-02-16 09:59:56 -0800579// TODO(bugs.webrtc.org/8878)
580#if defined(WEBRTC_MAC)
581#define MAYBE_UpDownUpTransportSequenceNumberRtx \
582 DISABLED_UpDownUpTransportSequenceNumberRtx
583#else
584#define MAYBE_UpDownUpTransportSequenceNumberRtx \
585 UpDownUpTransportSequenceNumberRtx
586#endif
587TEST_F(RampUpTest, MAYBE_UpDownUpTransportSequenceNumberRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800588 std::vector<int> loss_rates = {0, 0, 0, 0};
589 RampUpDownUpTester test(3, 0, 0, kStartBitrateBps,
isheriff6f8d6862016-05-26 11:24:55 -0700590 RtpExtension::kTransportSequenceNumberUri, true,
stefan45b5fe52017-03-09 06:27:02 -0800591 false, loss_rates, true);
philipel5ef2bc12017-02-21 07:28:31 -0800592 RunBaseTest(&test);
593}
594
stefan45b5fe52017-03-09 06:27:02 -0800595// TODO(holmer): Tests which don't report perf stats should be moved to a
596// different executable since they per definition are not perf tests.
Taylor Brandstetter05d98222017-10-10 12:12:53 -0700597// This test is disabled because it crashes on Linux, and is flaky on other
598// platforms. See: crbug.com/webrtc/7919
599TEST_F(RampUpTest, DISABLED_UpDownUpTransportSequenceNumberPacketLoss) {
philipel5ef2bc12017-02-21 07:28:31 -0800600 std::vector<int> loss_rates = {20, 0, 0, 0};
601 RampUpDownUpTester test(1, 0, 1, kStartBitrateBps,
602 RtpExtension::kTransportSequenceNumberUri, true,
stefan45b5fe52017-03-09 06:27:02 -0800603 false, loss_rates, false);
Stefan Holmerff2a6352016-01-14 10:00:21 +0100604 RunBaseTest(&test);
605}
606
Taylor Brandstetterab86e7f2018-02-12 15:16:02 -0800607// TODO(bugs.webrtc.org/8878)
608#if defined(WEBRTC_MAC)
609#define MAYBE_UpDownUpAudioVideoTransportSequenceNumberRtx \
610 DISABLED_UpDownUpAudioVideoTransportSequenceNumberRtx
611#else
612#define MAYBE_UpDownUpAudioVideoTransportSequenceNumberRtx \
613 UpDownUpAudioVideoTransportSequenceNumberRtx
614#endif
615TEST_F(RampUpTest, MAYBE_UpDownUpAudioVideoTransportSequenceNumberRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800616 std::vector<int> loss_rates = {0, 0, 0, 0};
617 RampUpDownUpTester test(3, 1, 0, kStartBitrateBps,
isheriff6f8d6862016-05-26 11:24:55 -0700618 RtpExtension::kTransportSequenceNumberUri, true,
stefanff2ebf52017-03-13 01:27:03 -0700619 false, loss_rates, false);
Stefan Holmerff2a6352016-01-14 10:00:21 +0100620 RunBaseTest(&test);
621}
622
stefan38d8b3c2017-01-09 04:19:24 -0800623TEST_F(RampUpTest, UpDownUpAudioTransportSequenceNumberRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800624 std::vector<int> loss_rates = {0, 0, 0, 0};
625 RampUpDownUpTester test(0, 1, 0, kStartBitrateBps,
mflodman86cc6ff2016-07-26 04:44:06 -0700626 RtpExtension::kTransportSequenceNumberUri, true,
stefanff2ebf52017-03-13 01:27:03 -0700627 false, loss_rates, false);
mflodman86cc6ff2016-07-26 04:44:06 -0700628 RunBaseTest(&test);
629}
630
stefan38d8b3c2017-01-09 04:19:24 -0800631TEST_F(RampUpTest, TOffsetSimulcastRedRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800632 RampUpTester test(3, 0, 0, 0, 0, RtpExtension::kTimestampOffsetUri, true,
633 true, true);
stefan38d8b3c2017-01-09 04:19:24 -0800634 RunBaseTest(&test);
635}
636
637TEST_F(RampUpTest, AbsSendTime) {
philipel5ef2bc12017-02-21 07:28:31 -0800638 RampUpTester test(1, 0, 0, 0, 0, RtpExtension::kAbsSendTimeUri, false, false,
stefanff2ebf52017-03-13 01:27:03 -0700639 false);
stefane74eef12016-01-08 06:47:13 -0800640 RunBaseTest(&test);
pbos@webrtc.org85bd53e2014-12-10 10:36:20 +0000641}
642
stefan38d8b3c2017-01-09 04:19:24 -0800643TEST_F(RampUpTest, AbsSendTimeSimulcastRedRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800644 RampUpTester test(3, 0, 0, 0, 0, RtpExtension::kAbsSendTimeUri, true, true,
stefan5a2c5062017-01-27 06:43:18 -0800645 true);
stefane74eef12016-01-08 06:47:13 -0800646 RunBaseTest(&test);
pbos@webrtc.org85bd53e2014-12-10 10:36:20 +0000647}
648
stefan38d8b3c2017-01-09 04:19:24 -0800649TEST_F(RampUpTest, TransportSequenceNumber) {
philipel5ef2bc12017-02-21 07:28:31 -0800650 RampUpTester test(1, 0, 0, 0, 0, RtpExtension::kTransportSequenceNumberUri,
stefanff2ebf52017-03-13 01:27:03 -0700651 false, false, false);
stefane74eef12016-01-08 06:47:13 -0800652 RunBaseTest(&test);
Erik Språng6b8d3552015-09-24 15:06:57 +0200653}
654
655TEST_F(RampUpTest, TransportSequenceNumberSimulcast) {
philipel5ef2bc12017-02-21 07:28:31 -0800656 RampUpTester test(3, 0, 0, 0, 0, RtpExtension::kTransportSequenceNumberUri,
stefanff2ebf52017-03-13 01:27:03 -0700657 false, false, false);
stefane74eef12016-01-08 06:47:13 -0800658 RunBaseTest(&test);
Erik Språng6b8d3552015-09-24 15:06:57 +0200659}
660
stefan38d8b3c2017-01-09 04:19:24 -0800661TEST_F(RampUpTest, TransportSequenceNumberSimulcastRedRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800662 RampUpTester test(3, 0, 0, 0, 0, RtpExtension::kTransportSequenceNumberUri,
stefan5a2c5062017-01-27 06:43:18 -0800663 true, true, true);
664 RunBaseTest(&test);
665}
666
Taylor Brandstetterab86e7f2018-02-12 15:16:02 -0800667// TODO(bugs.webrtc.org/8878)
668#if defined(WEBRTC_MAC)
669#define MAYBE_AudioTransportSequenceNumber DISABLED_AudioTransportSequenceNumber
670#else
671#define MAYBE_AudioTransportSequenceNumber AudioTransportSequenceNumber
672#endif
673TEST_F(RampUpTest, MAYBE_AudioTransportSequenceNumber) {
philipel5ef2bc12017-02-21 07:28:31 -0800674 RampUpTester test(0, 1, 0, 300000, 10000,
stefan5a2c5062017-01-27 06:43:18 -0800675 RtpExtension::kTransportSequenceNumberUri, false, false,
676 false);
stefane74eef12016-01-08 06:47:13 -0800677 RunBaseTest(&test);
Erik Språng6b8d3552015-09-24 15:06:57 +0200678}
pbos@webrtc.org744fbc72013-09-10 09:26:25 +0000679} // namespace webrtc