blob: 5128d50451003b3d265774c7a2d85659d053d2d5 [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
stefanff483612015-12-21 03:14:00 -080011#include "webrtc/call/rampup_tests.h"
12
pbos@webrtc.org2b4ce3a2015-03-23 13:12:24 +000013#include "webrtc/base/checks.h"
philipel5ef2bc12017-02-21 07:28:31 -080014#include "webrtc/base/logging.h"
pbos12411ef2015-11-23 14:47:56 -080015#include "webrtc/base/platform_thread.h"
perkjfa10b552016-10-02 23:45:26 -070016#include "webrtc/test/encoder_settings.h"
kwibergac9f8762016-09-30 22:29:43 -070017#include "webrtc/test/gtest.h"
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +000018#include "webrtc/test/testsupport/perf_test.h"
pbos@webrtc.org744fbc72013-09-10 09:26:25 +000019
20namespace webrtc {
pbos@webrtc.org29023282013-09-11 10:14:56 +000021namespace {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000022
Stefan Holmer723dff12015-10-05 14:59:41 +020023static const int64_t kPollIntervalMs = 20;
philipel5ef2bc12017-02-21 07:28:31 -080024static const int kExpectedHighVideoBitrateBps = 80000;
stefandb752f92016-12-05 08:23:40 -080025static const int kExpectedHighAudioBitrateBps = 30000;
26static const int kLowBandwidthLimitBps = 20000;
27static const int kExpectedLowBitrateBps = 20000;
pbos@webrtc.org29023282013-09-11 10:14:56 +000028
stefanff483612015-12-21 03:14:00 -080029std::vector<uint32_t> GenerateSsrcs(size_t num_streams, uint32_t ssrc_offset) {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000030 std::vector<uint32_t> ssrcs;
31 for (size_t i = 0; i != num_streams; ++i)
32 ssrcs.push_back(static_cast<uint32_t>(ssrc_offset + i));
33 return ssrcs;
34}
mflodman@webrtc.orgeb16b812014-06-16 08:57:39 +000035} // namespace
henrik.lundin@webrtc.org845862f2014-03-06 07:19:28 +000036
stefanff483612015-12-21 03:14:00 -080037RampUpTester::RampUpTester(size_t num_video_streams,
38 size_t num_audio_streams,
philipel5ef2bc12017-02-21 07:28:31 -080039 size_t num_flexfec_streams,
stefan4fbd1452015-09-28 03:57:14 -070040 unsigned int start_bitrate_bps,
stefan5a2c5062017-01-27 06:43:18 -080041 int64_t min_run_time_ms,
stefan4fbd1452015-09-28 03:57:14 -070042 const std::string& extension_type,
43 bool rtx,
stefan5a2c5062017-01-27 06:43:18 -080044 bool red,
45 bool report_perf_stats)
stefan4fbd1452015-09-28 03:57:14 -070046 : EndToEndTest(test::CallTest::kLongTimeoutMs),
tommi0f8b4032017-02-22 11:22:05 -080047 stop_event_(false, false),
stefan4fbd1452015-09-28 03:57:14 -070048 clock_(Clock::GetRealTimeClock()),
stefanff483612015-12-21 03:14:00 -080049 num_video_streams_(num_video_streams),
50 num_audio_streams_(num_audio_streams),
philipel5ef2bc12017-02-21 07:28:31 -080051 num_flexfec_streams_(num_flexfec_streams),
stefan4fbd1452015-09-28 03:57:14 -070052 rtx_(rtx),
53 red_(red),
stefan45b5fe52017-03-09 06:27:02 -080054 report_perf_stats_(report_perf_stats),
mflodman86cc6ff2016-07-26 04:44:06 -070055 sender_call_(nullptr),
stefan4fbd1452015-09-28 03:57:14 -070056 send_stream_(nullptr),
sprang4847ae62017-06-27 07:06:52 -070057 send_transport_(nullptr),
stefan4fbd1452015-09-28 03:57:14 -070058 start_bitrate_bps_(start_bitrate_bps),
stefan5a2c5062017-01-27 06:43:18 -080059 min_run_time_ms_(min_run_time_ms),
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000060 expected_bitrate_bps_(0),
Erik Språngf3a7c9d2015-10-05 14:03:22 +020061 test_start_ms_(-1),
stefan4fbd1452015-09-28 03:57:14 -070062 ramp_up_finished_ms_(-1),
63 extension_type_(extension_type),
stefanff483612015-12-21 03:14:00 -080064 video_ssrcs_(GenerateSsrcs(num_video_streams_, 100)),
65 video_rtx_ssrcs_(GenerateSsrcs(num_video_streams_, 200)),
66 audio_ssrcs_(GenerateSsrcs(num_audio_streams_, 300)),
Peter Boström8c38e8b2015-11-26 17:45:47 +010067 poller_thread_(&BitrateStatsPollingThread,
68 this,
mflodman86cc6ff2016-07-26 04:44:06 -070069 "BitrateStatsPollingThread") {
philipel5ef2bc12017-02-21 07:28:31 -080070 if (red_)
71 EXPECT_EQ(0u, num_flexfec_streams_);
Stefan Holmerff2a6352016-01-14 10:00:21 +010072 EXPECT_LE(num_audio_streams_, 1u);
stefan4fbd1452015-09-28 03:57:14 -070073}
74
75RampUpTester::~RampUpTester() {
stefan4fbd1452015-09-28 03:57:14 -070076}
77
78Call::Config RampUpTester::GetSenderCallConfig() {
skvlad11a9cbf2016-10-07 11:53:05 -070079 Call::Config call_config(&event_log_);
stefan4fbd1452015-09-28 03:57:14 -070080 if (start_bitrate_bps_ != 0) {
81 call_config.bitrate_config.start_bitrate_bps = start_bitrate_bps_;
82 }
83 call_config.bitrate_config.min_bitrate_bps = 10000;
84 return call_config;
85}
86
stefanff483612015-12-21 03:14:00 -080087void RampUpTester::OnVideoStreamsCreated(
stefan4fbd1452015-09-28 03:57:14 -070088 VideoSendStream* send_stream,
89 const std::vector<VideoReceiveStream*>& receive_streams) {
90 send_stream_ = send_stream;
91}
92
stefane74eef12016-01-08 06:47:13 -080093test::PacketTransport* RampUpTester::CreateSendTransport(Call* sender_call) {
minyue20c84cc2017-04-10 16:57:57 -070094 send_transport_ = new test::PacketTransport(
95 sender_call, this, test::PacketTransport::kSender,
96 test::CallTest::payload_type_map_, forward_transport_config_);
stefane74eef12016-01-08 06:47:13 -080097 return send_transport_;
stefanf116bd02015-10-27 08:29:42 -070098}
99
Stefan Holmerd20e6512016-01-12 15:51:22 +0100100size_t RampUpTester::GetNumVideoStreams() const {
101 return num_video_streams_;
102}
103
Stefan Holmerff2a6352016-01-14 10:00:21 +0100104size_t RampUpTester::GetNumAudioStreams() const {
105 return num_audio_streams_;
106}
107
philipel5ef2bc12017-02-21 07:28:31 -0800108size_t RampUpTester::GetNumFlexfecStreams() const {
109 return num_flexfec_streams_;
110}
111
perkjfa10b552016-10-02 23:45:26 -0700112class RampUpTester::VideoStreamFactory
113 : public VideoEncoderConfig::VideoStreamFactoryInterface {
114 public:
115 VideoStreamFactory() {}
116
117 private:
118 std::vector<VideoStream> CreateEncoderStreams(
119 int width,
120 int height,
121 const VideoEncoderConfig& encoder_config) override {
122 std::vector<VideoStream> streams =
123 test::CreateVideoStreams(width, height, encoder_config);
124 if (encoder_config.number_of_streams == 1) {
125 streams[0].target_bitrate_bps = streams[0].max_bitrate_bps = 2000000;
126 }
127 return streams;
128 }
129};
130
stefanff483612015-12-21 03:14:00 -0800131void RampUpTester::ModifyVideoConfigs(
stefan4fbd1452015-09-28 03:57:14 -0700132 VideoSendStream::Config* send_config,
133 std::vector<VideoReceiveStream::Config>* receive_configs,
134 VideoEncoderConfig* encoder_config) {
135 send_config->suspend_below_min_bitrate = true;
perkjfa10b552016-10-02 23:45:26 -0700136 encoder_config->number_of_streams = num_video_streams_;
137 encoder_config->max_bitrate_bps = 2000000;
138 encoder_config->video_stream_factory =
139 new rtc::RefCountedObject<RampUpTester::VideoStreamFactory>();
stefanff483612015-12-21 03:14:00 -0800140 if (num_video_streams_ == 1) {
stefan4fbd1452015-09-28 03:57:14 -0700141 // For single stream rampup until 1mbps
142 expected_bitrate_bps_ = kSingleStreamTargetBps;
143 } else {
144 // For multi stream rampup until all streams are being sent. That means
perkjfa10b552016-10-02 23:45:26 -0700145 // enough bitrate to send all the target streams plus the min bitrate of
stefan4fbd1452015-09-28 03:57:14 -0700146 // the last one.
perkjfa10b552016-10-02 23:45:26 -0700147 std::vector<VideoStream> streams = test::CreateVideoStreams(
148 test::CallTest::kDefaultWidth, test::CallTest::kDefaultHeight,
149 *encoder_config);
150 expected_bitrate_bps_ = streams.back().min_bitrate_bps;
151 for (size_t i = 0; i < streams.size() - 1; ++i) {
152 expected_bitrate_bps_ += streams[i].target_bitrate_bps;
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000153 }
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000154 }
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000155
stefan4fbd1452015-09-28 03:57:14 -0700156 send_config->rtp.extensions.clear();
157
158 bool remb;
stefan43edf0f2015-11-20 18:05:48 -0800159 bool transport_cc;
isheriff6f8d6862016-05-26 11:24:55 -0700160 if (extension_type_ == RtpExtension::kAbsSendTimeUri) {
stefan4fbd1452015-09-28 03:57:14 -0700161 remb = true;
stefan43edf0f2015-11-20 18:05:48 -0800162 transport_cc = false;
stefan4fbd1452015-09-28 03:57:14 -0700163 send_config->rtp.extensions.push_back(
164 RtpExtension(extension_type_.c_str(), kAbsSendTimeExtensionId));
isheriff6f8d6862016-05-26 11:24:55 -0700165 } else if (extension_type_ == RtpExtension::kTransportSequenceNumberUri) {
stefan4fbd1452015-09-28 03:57:14 -0700166 remb = false;
stefan43edf0f2015-11-20 18:05:48 -0800167 transport_cc = true;
stefan4fbd1452015-09-28 03:57:14 -0700168 send_config->rtp.extensions.push_back(RtpExtension(
169 extension_type_.c_str(), kTransportSequenceNumberExtensionId));
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000170 } else {
stefan4fbd1452015-09-28 03:57:14 -0700171 remb = true;
stefan43edf0f2015-11-20 18:05:48 -0800172 transport_cc = false;
stefan4fbd1452015-09-28 03:57:14 -0700173 send_config->rtp.extensions.push_back(RtpExtension(
174 extension_type_.c_str(), kTransmissionTimeOffsetExtensionId));
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000175 }
stefan4fbd1452015-09-28 03:57:14 -0700176
177 send_config->rtp.nack.rtp_history_ms = test::CallTest::kNackRtpHistoryMs;
stefanff483612015-12-21 03:14:00 -0800178 send_config->rtp.ssrcs = video_ssrcs_;
stefan4fbd1452015-09-28 03:57:14 -0700179 if (rtx_) {
180 send_config->rtp.rtx.payload_type = test::CallTest::kSendRtxPayloadType;
stefanff483612015-12-21 03:14:00 -0800181 send_config->rtp.rtx.ssrcs = video_rtx_ssrcs_;
stefan4fbd1452015-09-28 03:57:14 -0700182 }
183 if (red_) {
brandtrb5f2c3f2016-10-04 23:28:39 -0700184 send_config->rtp.ulpfec.ulpfec_payload_type =
stefan4fbd1452015-09-28 03:57:14 -0700185 test::CallTest::kUlpfecPayloadType;
brandtrb5f2c3f2016-10-04 23:28:39 -0700186 send_config->rtp.ulpfec.red_payload_type = test::CallTest::kRedPayloadType;
brandtrfbfb5362016-11-17 04:18:37 -0800187 if (rtx_) {
188 send_config->rtp.ulpfec.red_rtx_payload_type =
189 test::CallTest::kRtxRedPayloadType;
190 }
stefan4fbd1452015-09-28 03:57:14 -0700191 }
192
193 size_t i = 0;
194 for (VideoReceiveStream::Config& recv_config : *receive_configs) {
195 recv_config.rtp.remb = remb;
stefan43edf0f2015-11-20 18:05:48 -0800196 recv_config.rtp.transport_cc = transport_cc;
stefan4fbd1452015-09-28 03:57:14 -0700197 recv_config.rtp.extensions = send_config->rtp.extensions;
198
stefanff483612015-12-21 03:14:00 -0800199 recv_config.rtp.remote_ssrc = video_ssrcs_[i];
stefan4fbd1452015-09-28 03:57:14 -0700200 recv_config.rtp.nack.rtp_history_ms = send_config->rtp.nack.rtp_history_ms;
201
202 if (red_) {
brandtrb5f2c3f2016-10-04 23:28:39 -0700203 recv_config.rtp.ulpfec.red_payload_type =
204 send_config->rtp.ulpfec.red_payload_type;
205 recv_config.rtp.ulpfec.ulpfec_payload_type =
206 send_config->rtp.ulpfec.ulpfec_payload_type;
brandtrfbfb5362016-11-17 04:18:37 -0800207 if (rtx_) {
208 recv_config.rtp.ulpfec.red_rtx_payload_type =
209 send_config->rtp.ulpfec.red_rtx_payload_type;
210 }
stefan4fbd1452015-09-28 03:57:14 -0700211 }
212
213 if (rtx_) {
brandtr14742122017-01-27 04:53:07 -0800214 recv_config.rtp.rtx_ssrc = video_rtx_ssrcs_[i];
215 recv_config.rtp
216 .rtx_payload_types[send_config->encoder_settings.payload_type] =
217 send_config->rtp.rtx.payload_type;
stefan4fbd1452015-09-28 03:57:14 -0700218 }
219 ++i;
220 }
philipel5ef2bc12017-02-21 07:28:31 -0800221
222 RTC_DCHECK_LE(num_flexfec_streams_, 1);
223 if (num_flexfec_streams_ == 1) {
224 send_config->rtp.flexfec.payload_type = test::CallTest::kFlexfecPayloadType;
225 send_config->rtp.flexfec.ssrc = test::CallTest::kFlexfecSendSsrc;
226 send_config->rtp.flexfec.protected_media_ssrcs = {video_ssrcs_[0]};
227 }
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000228}
229
Stefan Holmerff2a6352016-01-14 10:00:21 +0100230void RampUpTester::ModifyAudioConfigs(
231 AudioSendStream::Config* send_config,
232 std::vector<AudioReceiveStream::Config>* receive_configs) {
233 if (num_audio_streams_ == 0)
234 return;
235
isheriff6f8d6862016-05-26 11:24:55 -0700236 EXPECT_NE(RtpExtension::kTimestampOffsetUri, extension_type_)
Stefan Holmerff2a6352016-01-14 10:00:21 +0100237 << "Audio BWE not supported with toffset.";
philipel5ef2bc12017-02-21 07:28:31 -0800238 EXPECT_NE(RtpExtension::kAbsSendTimeUri, extension_type_)
239 << "Audio BWE not supported with abs-send-time.";
Stefan Holmerff2a6352016-01-14 10:00:21 +0100240
241 send_config->rtp.ssrc = audio_ssrcs_[0];
242 send_config->rtp.extensions.clear();
243
minyue10cbb462016-11-07 09:29:22 -0800244 send_config->min_bitrate_bps = 6000;
245 send_config->max_bitrate_bps = 60000;
mflodman86cc6ff2016-07-26 04:44:06 -0700246
Stefan Holmerff2a6352016-01-14 10:00:21 +0100247 bool transport_cc = false;
philipel5ef2bc12017-02-21 07:28:31 -0800248 if (extension_type_ == RtpExtension::kTransportSequenceNumberUri) {
Stefan Holmerff2a6352016-01-14 10:00:21 +0100249 transport_cc = true;
250 send_config->rtp.extensions.push_back(RtpExtension(
251 extension_type_.c_str(), kTransportSequenceNumberExtensionId));
252 }
253
254 for (AudioReceiveStream::Config& recv_config : *receive_configs) {
Stefan Holmerff2a6352016-01-14 10:00:21 +0100255 recv_config.rtp.transport_cc = transport_cc;
256 recv_config.rtp.extensions = send_config->rtp.extensions;
257 recv_config.rtp.remote_ssrc = send_config->rtp.ssrc;
258 }
259}
260
philipel5ef2bc12017-02-21 07:28:31 -0800261void RampUpTester::ModifyFlexfecConfigs(
262 std::vector<FlexfecReceiveStream::Config>* receive_configs) {
263 if (num_flexfec_streams_ == 0)
264 return;
265 RTC_DCHECK_EQ(1, num_flexfec_streams_);
266 (*receive_configs)[0].payload_type = test::CallTest::kFlexfecPayloadType;
267 (*receive_configs)[0].remote_ssrc = test::CallTest::kFlexfecSendSsrc;
268 (*receive_configs)[0].protected_media_ssrcs = {video_ssrcs_[0]};
269 (*receive_configs)[0].local_ssrc = video_ssrcs_[0];
270 if (extension_type_ == RtpExtension::kAbsSendTimeUri) {
271 (*receive_configs)[0].transport_cc = false;
272 (*receive_configs)[0].rtp_header_extensions.push_back(
273 RtpExtension(extension_type_.c_str(), kAbsSendTimeExtensionId));
274 } else if (extension_type_ == RtpExtension::kTransportSequenceNumberUri) {
275 (*receive_configs)[0].transport_cc = true;
276 (*receive_configs)[0].rtp_header_extensions.push_back(RtpExtension(
277 extension_type_.c_str(), kTransportSequenceNumberExtensionId));
278 }
279}
280
stefan4fbd1452015-09-28 03:57:14 -0700281void RampUpTester::OnCallsCreated(Call* sender_call, Call* receiver_call) {
282 sender_call_ = sender_call;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000283}
284
tommi0f8b4032017-02-22 11:22:05 -0800285void RampUpTester::BitrateStatsPollingThread(void* obj) {
286 static_cast<RampUpTester*>(obj)->PollStats();
pbos@webrtc.org32452b22014-10-22 12:15:24 +0000287}
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000288
tommi0f8b4032017-02-22 11:22:05 -0800289void RampUpTester::PollStats() {
290 do {
291 if (sender_call_) {
292 Call::Stats stats = sender_call_->GetStats();
stefan4fbd1452015-09-28 03:57:14 -0700293
tommi0f8b4032017-02-22 11:22:05 -0800294 EXPECT_GE(stats.send_bandwidth_bps, start_bitrate_bps_);
295 EXPECT_GE(expected_bitrate_bps_, 0);
296 if (stats.send_bandwidth_bps >= expected_bitrate_bps_ &&
297 (min_run_time_ms_ == -1 ||
298 clock_->TimeInMilliseconds() - test_start_ms_ >= min_run_time_ms_)) {
299 ramp_up_finished_ms_ = clock_->TimeInMilliseconds();
300 observation_complete_.Set();
301 }
stefan4fbd1452015-09-28 03:57:14 -0700302 }
tommi0f8b4032017-02-22 11:22:05 -0800303 } while (!stop_event_.Wait(kPollIntervalMs));
Erik Språng468e62a2015-07-06 10:50:47 +0200304}
305
stefan4fbd1452015-09-28 03:57:14 -0700306void RampUpTester::ReportResult(const std::string& measurement,
307 size_t value,
308 const std::string& units) const {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000309 webrtc::test::PrintResult(
310 measurement, "",
stefanff483612015-12-21 03:14:00 -0800311 ::testing::UnitTest::GetInstance()->current_test_info()->name(), value,
312 units, false);
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000313}
314
stefan092508a2015-09-29 02:26:42 -0700315void RampUpTester::AccumulateStats(const VideoSendStream::StreamStats& stream,
316 size_t* total_packets_sent,
317 size_t* total_sent,
318 size_t* padding_sent,
319 size_t* media_sent) const {
stefan4fbd1452015-09-28 03:57:14 -0700320 *total_packets_sent += stream.rtp_stats.transmitted.packets +
321 stream.rtp_stats.retransmitted.packets +
322 stream.rtp_stats.fec.packets;
323 *total_sent += stream.rtp_stats.transmitted.TotalBytes() +
324 stream.rtp_stats.retransmitted.TotalBytes() +
325 stream.rtp_stats.fec.TotalBytes();
326 *padding_sent += stream.rtp_stats.transmitted.padding_bytes +
327 stream.rtp_stats.retransmitted.padding_bytes +
328 stream.rtp_stats.fec.padding_bytes;
329 *media_sent += stream.rtp_stats.MediaPayloadBytes();
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000330}
331
stefan4fbd1452015-09-28 03:57:14 -0700332void RampUpTester::TriggerTestDone() {
Erik Språngf3a7c9d2015-10-05 14:03:22 +0200333 RTC_DCHECK_GE(test_start_ms_, 0);
334
Stefan Holmerff2a6352016-01-14 10:00:21 +0100335 // TODO(holmer): Add audio send stats here too when those APIs are available.
mflodman86cc6ff2016-07-26 04:44:06 -0700336 if (!send_stream_)
337 return;
338
stefan4fbd1452015-09-28 03:57:14 -0700339 VideoSendStream::Stats send_stats = send_stream_->GetStats();
340
341 size_t total_packets_sent = 0;
342 size_t total_sent = 0;
343 size_t padding_sent = 0;
344 size_t media_sent = 0;
stefanff483612015-12-21 03:14:00 -0800345 for (uint32_t ssrc : video_ssrcs_) {
stefan092508a2015-09-29 02:26:42 -0700346 AccumulateStats(send_stats.substreams[ssrc], &total_packets_sent,
347 &total_sent, &padding_sent, &media_sent);
stefan4fbd1452015-09-28 03:57:14 -0700348 }
349
350 size_t rtx_total_packets_sent = 0;
351 size_t rtx_total_sent = 0;
352 size_t rtx_padding_sent = 0;
353 size_t rtx_media_sent = 0;
stefanff483612015-12-21 03:14:00 -0800354 for (uint32_t rtx_ssrc : video_rtx_ssrcs_) {
stefan092508a2015-09-29 02:26:42 -0700355 AccumulateStats(send_stats.substreams[rtx_ssrc], &rtx_total_packets_sent,
356 &rtx_total_sent, &rtx_padding_sent, &rtx_media_sent);
stefan4fbd1452015-09-28 03:57:14 -0700357 }
358
stefan5a2c5062017-01-27 06:43:18 -0800359 if (report_perf_stats_) {
stefan5a2c5062017-01-27 06:43:18 -0800360 ReportResult("ramp-up-media-sent", media_sent, "bytes");
361 ReportResult("ramp-up-padding-sent", padding_sent, "bytes");
stefan5a2c5062017-01-27 06:43:18 -0800362 ReportResult("ramp-up-rtx-media-sent", rtx_media_sent, "bytes");
363 ReportResult("ramp-up-rtx-padding-sent", rtx_padding_sent, "bytes");
364 if (ramp_up_finished_ms_ >= 0) {
365 ReportResult("ramp-up-time", ramp_up_finished_ms_ - test_start_ms_,
366 "milliseconds");
367 }
368 ReportResult("ramp-up-average-network-latency",
369 send_transport_->GetAverageDelayMs(), "milliseconds");
stefan4fbd1452015-09-28 03:57:14 -0700370 }
371}
372
373void RampUpTester::PerformTest() {
Erik Språngf3a7c9d2015-10-05 14:03:22 +0200374 test_start_ms_ = clock_->TimeInMilliseconds();
Peter Boström8c38e8b2015-11-26 17:45:47 +0100375 poller_thread_.Start();
Peter Boström5811a392015-12-10 13:02:50 +0100376 EXPECT_TRUE(Wait()) << "Timed out while waiting for ramp-up to complete.";
stefan4fbd1452015-09-28 03:57:14 -0700377 TriggerTestDone();
tommi0f8b4032017-02-22 11:22:05 -0800378 stop_event_.Set();
Peter Boström8c38e8b2015-11-26 17:45:47 +0100379 poller_thread_.Stop();
stefan4fbd1452015-09-28 03:57:14 -0700380}
381
Stefan Holmerff2a6352016-01-14 10:00:21 +0100382RampUpDownUpTester::RampUpDownUpTester(size_t num_video_streams,
383 size_t num_audio_streams,
philipel5ef2bc12017-02-21 07:28:31 -0800384 size_t num_flexfec_streams,
stefan4fbd1452015-09-28 03:57:14 -0700385 unsigned int start_bitrate_bps,
386 const std::string& extension_type,
387 bool rtx,
philipel5ef2bc12017-02-21 07:28:31 -0800388 bool red,
stefan45b5fe52017-03-09 06:27:02 -0800389 const std::vector<int>& loss_rates,
390 bool report_perf_stats)
Stefan Holmerff2a6352016-01-14 10:00:21 +0100391 : RampUpTester(num_video_streams,
392 num_audio_streams,
philipel5ef2bc12017-02-21 07:28:31 -0800393 num_flexfec_streams,
Stefan Holmerff2a6352016-01-14 10:00:21 +0100394 start_bitrate_bps,
stefan5a2c5062017-01-27 06:43:18 -0800395 0,
Stefan Holmerff2a6352016-01-14 10:00:21 +0100396 extension_type,
397 rtx,
stefan5a2c5062017-01-27 06:43:18 -0800398 red,
stefan45b5fe52017-03-09 06:27:02 -0800399 report_perf_stats),
stefan76d9c9c2017-04-01 06:51:09 -0700400 link_rates_({4 * GetExpectedHighBitrate() / (3 * 1000),
401 kLowBandwidthLimitBps / 1000,
402 4 * GetExpectedHighBitrate() / (3 * 1000), 0}),
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000403 test_state_(kFirstRampup),
philipel5ef2bc12017-02-21 07:28:31 -0800404 next_state_(kTransitionToNextState),
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000405 state_start_ms_(clock_->TimeInMilliseconds()),
stefan4fbd1452015-09-28 03:57:14 -0700406 interval_start_ms_(clock_->TimeInMilliseconds()),
philipel5ef2bc12017-02-21 07:28:31 -0800407 sent_bytes_(0),
408 loss_rates_(loss_rates) {
409 forward_transport_config_.link_capacity_kbps = link_rates_[test_state_];
410 forward_transport_config_.queue_delay_ms = 100;
411 forward_transport_config_.loss_percent = loss_rates_[test_state_];
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000412}
413
stefan4fbd1452015-09-28 03:57:14 -0700414RampUpDownUpTester::~RampUpDownUpTester() {}
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000415
tommi0f8b4032017-02-22 11:22:05 -0800416void RampUpDownUpTester::PollStats() {
417 do {
418 if (send_stream_) {
419 webrtc::VideoSendStream::Stats stats = send_stream_->GetStats();
420 int transmit_bitrate_bps = 0;
421 for (auto it : stats.substreams) {
422 transmit_bitrate_bps += it.second.total_bitrate_bps;
423 }
424 EvolveTestState(transmit_bitrate_bps, stats.suspended);
425 } else if (num_audio_streams_ > 0 && sender_call_ != nullptr) {
426 // An audio send stream doesn't have bitrate stats, so the call send BW is
427 // currently used instead.
428 int transmit_bitrate_bps = sender_call_->GetStats().send_bandwidth_bps;
429 EvolveTestState(transmit_bitrate_bps, false);
mflodman@webrtc.orgeb16b812014-06-16 08:57:39 +0000430 }
tommi0f8b4032017-02-22 11:22:05 -0800431 } while (!stop_event_.Wait(kPollIntervalMs));
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000432}
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000433
stefan4fbd1452015-09-28 03:57:14 -0700434Call::Config RampUpDownUpTester::GetReceiverCallConfig() {
skvlad11a9cbf2016-10-07 11:53:05 -0700435 Call::Config config(&event_log_);
stefan4fbd1452015-09-28 03:57:14 -0700436 config.bitrate_config.min_bitrate_bps = 10000;
437 return config;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000438}
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000439
stefan4fbd1452015-09-28 03:57:14 -0700440std::string RampUpDownUpTester::GetModifierString() const {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000441 std::string str("_");
stefanff483612015-12-21 03:14:00 -0800442 if (num_video_streams_ > 0) {
443 std::ostringstream s;
444 s << num_video_streams_;
445 str += s.str();
446 str += "stream";
447 str += (num_video_streams_ > 1 ? "s" : "");
448 str += "_";
449 }
450 if (num_audio_streams_ > 0) {
451 std::ostringstream s;
452 s << num_audio_streams_;
453 str += s.str();
454 str += "stream";
455 str += (num_audio_streams_ > 1 ? "s" : "");
456 str += "_";
457 }
stefan4fbd1452015-09-28 03:57:14 -0700458 str += (rtx_ ? "" : "no");
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000459 str += "rtx";
460 return str;
461}
andresp@webrtc.orgc1480792014-03-20 03:23:55 +0000462
stefandb752f92016-12-05 08:23:40 -0800463int RampUpDownUpTester::GetExpectedHighBitrate() const {
stefan38d8b3c2017-01-09 04:19:24 -0800464 int expected_bitrate_bps = 0;
465 if (num_audio_streams_ > 0)
466 expected_bitrate_bps += kExpectedHighAudioBitrateBps;
467 if (num_video_streams_ > 0)
468 expected_bitrate_bps += kExpectedHighVideoBitrateBps;
469 return expected_bitrate_bps;
470}
471
philipel5ef2bc12017-02-21 07:28:31 -0800472size_t RampUpDownUpTester::GetFecBytes() const {
473 size_t flex_fec_bytes = 0;
474 if (num_flexfec_streams_ > 0) {
475 webrtc::VideoSendStream::Stats stats = send_stream_->GetStats();
476 for (const auto& kv : stats.substreams)
477 flex_fec_bytes += kv.second.rtp_stats.fec.TotalBytes();
478 }
479 return flex_fec_bytes;
480}
481
482bool RampUpDownUpTester::ExpectingFec() const {
483 return num_flexfec_streams_ > 0 && forward_transport_config_.loss_percent > 0;
484}
485
stefan4fbd1452015-09-28 03:57:14 -0700486void RampUpDownUpTester::EvolveTestState(int bitrate_bps, bool suspended) {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000487 int64_t now = clock_->TimeInMilliseconds();
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000488 switch (test_state_) {
philipel5ef2bc12017-02-21 07:28:31 -0800489 case kFirstRampup:
stefan4fbd1452015-09-28 03:57:14 -0700490 EXPECT_FALSE(suspended);
stefandb752f92016-12-05 08:23:40 -0800491 if (bitrate_bps >= GetExpectedHighBitrate()) {
stefan45b5fe52017-03-09 06:27:02 -0800492 if (report_perf_stats_) {
493 webrtc::test::PrintResult("ramp_up_down_up", GetModifierString(),
494 "first_rampup", now - state_start_ms_, "ms",
495 false);
496 }
philipel5ef2bc12017-02-21 07:28:31 -0800497 // Apply loss during the transition between states if FEC is enabled.
498 forward_transport_config_.loss_percent = loss_rates_[test_state_];
499 test_state_ = kTransitionToNextState;
500 next_state_ = kLowRate;
andresp@webrtc.orgc1480792014-03-20 03:23:55 +0000501 }
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000502 break;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000503 case kLowRate: {
mflodman86cc6ff2016-07-26 04:44:06 -0700504 // Audio streams are never suspended.
505 bool check_suspend_state = num_video_streams_ > 0;
506 if (bitrate_bps < kExpectedLowBitrateBps &&
507 suspended == check_suspend_state) {
stefan45b5fe52017-03-09 06:27:02 -0800508 if (report_perf_stats_) {
509 webrtc::test::PrintResult("ramp_up_down_up", GetModifierString(),
510 "rampdown", now - state_start_ms_, "ms",
511 false);
512 }
philipel5ef2bc12017-02-21 07:28:31 -0800513 // Apply loss during the transition between states if FEC is enabled.
514 forward_transport_config_.loss_percent = loss_rates_[test_state_];
515 test_state_ = kTransitionToNextState;
516 next_state_ = kSecondRampup;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000517 }
518 break;
519 }
philipel5ef2bc12017-02-21 07:28:31 -0800520 case kSecondRampup:
stefandb752f92016-12-05 08:23:40 -0800521 if (bitrate_bps >= GetExpectedHighBitrate() && !suspended) {
stefan45b5fe52017-03-09 06:27:02 -0800522 if (report_perf_stats_) {
523 webrtc::test::PrintResult("ramp_up_down_up", GetModifierString(),
524 "second_rampup", now - state_start_ms_,
525 "ms", false);
526 ReportResult("ramp-up-down-up-average-network-latency",
527 send_transport_->GetAverageDelayMs(), "milliseconds");
528 }
philipel5ef2bc12017-02-21 07:28:31 -0800529 // Apply loss during the transition between states if FEC is enabled.
530 forward_transport_config_.loss_percent = loss_rates_[test_state_];
531 test_state_ = kTransitionToNextState;
532 next_state_ = kTestEnd;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000533 }
534 break;
philipel5ef2bc12017-02-21 07:28:31 -0800535 case kTestEnd:
536 observation_complete_.Set();
537 break;
538 case kTransitionToNextState:
539 if (!ExpectingFec() || GetFecBytes() > 0) {
540 test_state_ = next_state_;
541 forward_transport_config_.link_capacity_kbps = link_rates_[test_state_];
542 // No loss while ramping up and down as it may affect the BWE
543 // negatively, making the test flaky.
544 forward_transport_config_.loss_percent = 0;
545 state_start_ms_ = now;
546 interval_start_ms_ = now;
547 sent_bytes_ = 0;
548 send_transport_->SetConfig(forward_transport_config_);
549 }
550 break;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000551 }
552}
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +0000553
stefan4fbd1452015-09-28 03:57:14 -0700554class RampUpTest : public test::CallTest {
Erik Språng6b8d3552015-09-24 15:06:57 +0200555 public:
stefan4fbd1452015-09-28 03:57:14 -0700556 RampUpTest() {}
Erik Språng6b8d3552015-09-24 15:06:57 +0200557
stefan4fbd1452015-09-28 03:57:14 -0700558 virtual ~RampUpTest() {
stefanff483612015-12-21 03:14:00 -0800559 EXPECT_EQ(nullptr, video_send_stream_);
560 EXPECT_TRUE(video_receive_streams_.empty());
Erik Språng6b8d3552015-09-24 15:06:57 +0200561 }
Erik Språng6b8d3552015-09-24 15:06:57 +0200562};
563
Stefan Holmerff2a6352016-01-14 10:00:21 +0100564static const uint32_t kStartBitrateBps = 60000;
565
stefan38d8b3c2017-01-09 04:19:24 -0800566TEST_F(RampUpTest, UpDownUpAbsSendTimeSimulcastRedRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800567 std::vector<int> loss_rates = {0, 0, 0, 0};
568 RampUpDownUpTester test(3, 0, 0, kStartBitrateBps,
stefan45b5fe52017-03-09 06:27:02 -0800569 RtpExtension::kAbsSendTimeUri, true, true, loss_rates,
570 true);
stefane74eef12016-01-08 06:47:13 -0800571 RunBaseTest(&test);
Shao Changbine62202f2015-04-21 20:24:50 +0800572}
Stefan Holmerff2a6352016-01-14 10:00:21 +0100573
stefan38d8b3c2017-01-09 04:19:24 -0800574TEST_F(RampUpTest, UpDownUpTransportSequenceNumberRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800575 std::vector<int> loss_rates = {0, 0, 0, 0};
576 RampUpDownUpTester test(3, 0, 0, kStartBitrateBps,
isheriff6f8d6862016-05-26 11:24:55 -0700577 RtpExtension::kTransportSequenceNumberUri, true,
stefan45b5fe52017-03-09 06:27:02 -0800578 false, loss_rates, true);
philipel5ef2bc12017-02-21 07:28:31 -0800579 RunBaseTest(&test);
580}
581
stefan45b5fe52017-03-09 06:27:02 -0800582// TODO(holmer): Tests which don't report perf stats should be moved to a
583// different executable since they per definition are not perf tests.
philipel5ef2bc12017-02-21 07:28:31 -0800584TEST_F(RampUpTest, UpDownUpTransportSequenceNumberPacketLoss) {
585 std::vector<int> loss_rates = {20, 0, 0, 0};
586 RampUpDownUpTester test(1, 0, 1, kStartBitrateBps,
587 RtpExtension::kTransportSequenceNumberUri, true,
stefan45b5fe52017-03-09 06:27:02 -0800588 false, loss_rates, false);
Stefan Holmerff2a6352016-01-14 10:00:21 +0100589 RunBaseTest(&test);
590}
591
stefan38d8b3c2017-01-09 04:19:24 -0800592TEST_F(RampUpTest, UpDownUpAudioVideoTransportSequenceNumberRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800593 std::vector<int> loss_rates = {0, 0, 0, 0};
594 RampUpDownUpTester test(3, 1, 0, kStartBitrateBps,
isheriff6f8d6862016-05-26 11:24:55 -0700595 RtpExtension::kTransportSequenceNumberUri, true,
stefanff2ebf52017-03-13 01:27:03 -0700596 false, loss_rates, false);
Stefan Holmerff2a6352016-01-14 10:00:21 +0100597 RunBaseTest(&test);
598}
599
stefan38d8b3c2017-01-09 04:19:24 -0800600TEST_F(RampUpTest, UpDownUpAudioTransportSequenceNumberRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800601 std::vector<int> loss_rates = {0, 0, 0, 0};
602 RampUpDownUpTester test(0, 1, 0, kStartBitrateBps,
mflodman86cc6ff2016-07-26 04:44:06 -0700603 RtpExtension::kTransportSequenceNumberUri, true,
stefanff2ebf52017-03-13 01:27:03 -0700604 false, loss_rates, false);
mflodman86cc6ff2016-07-26 04:44:06 -0700605 RunBaseTest(&test);
606}
607
stefan38d8b3c2017-01-09 04:19:24 -0800608TEST_F(RampUpTest, TOffsetSimulcastRedRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800609 RampUpTester test(3, 0, 0, 0, 0, RtpExtension::kTimestampOffsetUri, true,
610 true, true);
stefan38d8b3c2017-01-09 04:19:24 -0800611 RunBaseTest(&test);
612}
613
614TEST_F(RampUpTest, AbsSendTime) {
philipel5ef2bc12017-02-21 07:28:31 -0800615 RampUpTester test(1, 0, 0, 0, 0, RtpExtension::kAbsSendTimeUri, false, false,
stefanff2ebf52017-03-13 01:27:03 -0700616 false);
stefane74eef12016-01-08 06:47:13 -0800617 RunBaseTest(&test);
pbos@webrtc.org85bd53e2014-12-10 10:36:20 +0000618}
619
stefan38d8b3c2017-01-09 04:19:24 -0800620TEST_F(RampUpTest, AbsSendTimeSimulcastRedRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800621 RampUpTester test(3, 0, 0, 0, 0, RtpExtension::kAbsSendTimeUri, true, true,
stefan5a2c5062017-01-27 06:43:18 -0800622 true);
stefane74eef12016-01-08 06:47:13 -0800623 RunBaseTest(&test);
pbos@webrtc.org85bd53e2014-12-10 10:36:20 +0000624}
625
stefan38d8b3c2017-01-09 04:19:24 -0800626TEST_F(RampUpTest, TransportSequenceNumber) {
philipel5ef2bc12017-02-21 07:28:31 -0800627 RampUpTester test(1, 0, 0, 0, 0, RtpExtension::kTransportSequenceNumberUri,
stefanff2ebf52017-03-13 01:27:03 -0700628 false, false, false);
stefane74eef12016-01-08 06:47:13 -0800629 RunBaseTest(&test);
Erik Språng6b8d3552015-09-24 15:06:57 +0200630}
631
632TEST_F(RampUpTest, TransportSequenceNumberSimulcast) {
philipel5ef2bc12017-02-21 07:28:31 -0800633 RampUpTester test(3, 0, 0, 0, 0, RtpExtension::kTransportSequenceNumberUri,
stefanff2ebf52017-03-13 01:27:03 -0700634 false, false, false);
stefane74eef12016-01-08 06:47:13 -0800635 RunBaseTest(&test);
Erik Språng6b8d3552015-09-24 15:06:57 +0200636}
637
stefan38d8b3c2017-01-09 04:19:24 -0800638TEST_F(RampUpTest, TransportSequenceNumberSimulcastRedRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800639 RampUpTester test(3, 0, 0, 0, 0, RtpExtension::kTransportSequenceNumberUri,
stefan5a2c5062017-01-27 06:43:18 -0800640 true, true, true);
641 RunBaseTest(&test);
642}
643
644TEST_F(RampUpTest, AudioTransportSequenceNumber) {
philipel5ef2bc12017-02-21 07:28:31 -0800645 RampUpTester test(0, 1, 0, 300000, 10000,
stefan5a2c5062017-01-27 06:43:18 -0800646 RtpExtension::kTransportSequenceNumberUri, false, false,
647 false);
stefane74eef12016-01-08 06:47:13 -0800648 RunBaseTest(&test);
Erik Språng6b8d3552015-09-24 15:06:57 +0200649}
pbos@webrtc.org744fbc72013-09-10 09:26:25 +0000650} // namespace webrtc