blob: a93dd7957cac47eea044fdd76ff4362bf4006836 [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"
16#include "test/encoder_settings.h"
17#include "test/gtest.h"
18#include "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;
Sebastian Jansson12fb1702018-02-23 11:34:18 +010027// Set target detected bitrate to slightly larger than the target bitrate to
28// avoid flakiness.
29static const int kLowBitrateMarginBps = 2000;
pbos@webrtc.org29023282013-09-11 10:14:56 +000030
stefanff483612015-12-21 03:14:00 -080031std::vector<uint32_t> GenerateSsrcs(size_t num_streams, uint32_t ssrc_offset) {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000032 std::vector<uint32_t> ssrcs;
33 for (size_t i = 0; i != num_streams; ++i)
34 ssrcs.push_back(static_cast<uint32_t>(ssrc_offset + i));
35 return ssrcs;
36}
mflodman@webrtc.orgeb16b812014-06-16 08:57:39 +000037} // namespace
henrik.lundin@webrtc.org845862f2014-03-06 07:19:28 +000038
stefanff483612015-12-21 03:14:00 -080039RampUpTester::RampUpTester(size_t num_video_streams,
40 size_t num_audio_streams,
philipel5ef2bc12017-02-21 07:28:31 -080041 size_t num_flexfec_streams,
stefan4fbd1452015-09-28 03:57:14 -070042 unsigned int start_bitrate_bps,
stefan5a2c5062017-01-27 06:43:18 -080043 int64_t min_run_time_ms,
stefan4fbd1452015-09-28 03:57:14 -070044 const std::string& extension_type,
45 bool rtx,
stefan5a2c5062017-01-27 06:43:18 -080046 bool red,
47 bool report_perf_stats)
stefan4fbd1452015-09-28 03:57:14 -070048 : EndToEndTest(test::CallTest::kLongTimeoutMs),
tommi0f8b4032017-02-22 11:22:05 -080049 stop_event_(false, false),
stefan4fbd1452015-09-28 03:57:14 -070050 clock_(Clock::GetRealTimeClock()),
stefanff483612015-12-21 03:14:00 -080051 num_video_streams_(num_video_streams),
52 num_audio_streams_(num_audio_streams),
philipel5ef2bc12017-02-21 07:28:31 -080053 num_flexfec_streams_(num_flexfec_streams),
stefan4fbd1452015-09-28 03:57:14 -070054 rtx_(rtx),
55 red_(red),
stefan45b5fe52017-03-09 06:27:02 -080056 report_perf_stats_(report_perf_stats),
mflodman86cc6ff2016-07-26 04:44:06 -070057 sender_call_(nullptr),
stefan4fbd1452015-09-28 03:57:14 -070058 send_stream_(nullptr),
sprang4847ae62017-06-27 07:06:52 -070059 send_transport_(nullptr),
stefan4fbd1452015-09-28 03:57:14 -070060 start_bitrate_bps_(start_bitrate_bps),
stefan5a2c5062017-01-27 06:43:18 -080061 min_run_time_ms_(min_run_time_ms),
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000062 expected_bitrate_bps_(0),
Erik Språngf3a7c9d2015-10-05 14:03:22 +020063 test_start_ms_(-1),
stefan4fbd1452015-09-28 03:57:14 -070064 ramp_up_finished_ms_(-1),
65 extension_type_(extension_type),
stefanff483612015-12-21 03:14:00 -080066 video_ssrcs_(GenerateSsrcs(num_video_streams_, 100)),
67 video_rtx_ssrcs_(GenerateSsrcs(num_video_streams_, 200)),
68 audio_ssrcs_(GenerateSsrcs(num_audio_streams_, 300)),
Peter Boström8c38e8b2015-11-26 17:45:47 +010069 poller_thread_(&BitrateStatsPollingThread,
70 this,
mflodman86cc6ff2016-07-26 04:44:06 -070071 "BitrateStatsPollingThread") {
philipel5ef2bc12017-02-21 07:28:31 -080072 if (red_)
73 EXPECT_EQ(0u, num_flexfec_streams_);
Stefan Holmerff2a6352016-01-14 10:00:21 +010074 EXPECT_LE(num_audio_streams_, 1u);
stefan4fbd1452015-09-28 03:57:14 -070075}
76
77RampUpTester::~RampUpTester() {
stefan4fbd1452015-09-28 03:57:14 -070078}
79
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] =
222 send_config->encoder_settings.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) {
450 std::ostringstream s;
451 s << num_video_streams_;
452 str += s.str();
453 str += "stream";
454 str += (num_video_streams_ > 1 ? "s" : "");
455 str += "_";
456 }
457 if (num_audio_streams_ > 0) {
458 std::ostringstream s;
459 s << num_audio_streams_;
460 str += s.str();
461 str += "stream";
462 str += (num_audio_streams_ > 1 ? "s" : "");
463 str += "_";
464 }
stefan4fbd1452015-09-28 03:57:14 -0700465 str += (rtx_ ? "" : "no");
Edward Lemurdd3987f2018-01-04 19:44:54 +0100466 str += "rtx_";
467 str += (red_ ? "" : "no");
468 str += "red";
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000469 return str;
470}
andresp@webrtc.orgc1480792014-03-20 03:23:55 +0000471
stefandb752f92016-12-05 08:23:40 -0800472int RampUpDownUpTester::GetExpectedHighBitrate() const {
stefan38d8b3c2017-01-09 04:19:24 -0800473 int expected_bitrate_bps = 0;
474 if (num_audio_streams_ > 0)
475 expected_bitrate_bps += kExpectedHighAudioBitrateBps;
476 if (num_video_streams_ > 0)
477 expected_bitrate_bps += kExpectedHighVideoBitrateBps;
478 return expected_bitrate_bps;
479}
480
philipel5ef2bc12017-02-21 07:28:31 -0800481size_t RampUpDownUpTester::GetFecBytes() const {
482 size_t flex_fec_bytes = 0;
483 if (num_flexfec_streams_ > 0) {
484 webrtc::VideoSendStream::Stats stats = send_stream_->GetStats();
485 for (const auto& kv : stats.substreams)
486 flex_fec_bytes += kv.second.rtp_stats.fec.TotalBytes();
487 }
488 return flex_fec_bytes;
489}
490
491bool RampUpDownUpTester::ExpectingFec() const {
492 return num_flexfec_streams_ > 0 && forward_transport_config_.loss_percent > 0;
493}
494
stefan4fbd1452015-09-28 03:57:14 -0700495void RampUpDownUpTester::EvolveTestState(int bitrate_bps, bool suspended) {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000496 int64_t now = clock_->TimeInMilliseconds();
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000497 switch (test_state_) {
philipel5ef2bc12017-02-21 07:28:31 -0800498 case kFirstRampup:
stefan4fbd1452015-09-28 03:57:14 -0700499 EXPECT_FALSE(suspended);
stefandb752f92016-12-05 08:23:40 -0800500 if (bitrate_bps >= GetExpectedHighBitrate()) {
stefan45b5fe52017-03-09 06:27:02 -0800501 if (report_perf_stats_) {
502 webrtc::test::PrintResult("ramp_up_down_up", GetModifierString(),
503 "first_rampup", now - state_start_ms_, "ms",
504 false);
505 }
philipel5ef2bc12017-02-21 07:28:31 -0800506 // Apply loss during the transition between states if FEC is enabled.
507 forward_transport_config_.loss_percent = loss_rates_[test_state_];
508 test_state_ = kTransitionToNextState;
509 next_state_ = kLowRate;
andresp@webrtc.orgc1480792014-03-20 03:23:55 +0000510 }
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000511 break;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000512 case kLowRate: {
mflodman86cc6ff2016-07-26 04:44:06 -0700513 // Audio streams are never suspended.
514 bool check_suspend_state = num_video_streams_ > 0;
Sebastian Jansson12fb1702018-02-23 11:34:18 +0100515 if (bitrate_bps < kLowBandwidthLimitBps + kLowBitrateMarginBps &&
mflodman86cc6ff2016-07-26 04:44:06 -0700516 suspended == check_suspend_state) {
stefan45b5fe52017-03-09 06:27:02 -0800517 if (report_perf_stats_) {
518 webrtc::test::PrintResult("ramp_up_down_up", GetModifierString(),
519 "rampdown", now - state_start_ms_, "ms",
520 false);
521 }
philipel5ef2bc12017-02-21 07:28:31 -0800522 // Apply loss during the transition between states if FEC is enabled.
523 forward_transport_config_.loss_percent = loss_rates_[test_state_];
524 test_state_ = kTransitionToNextState;
525 next_state_ = kSecondRampup;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000526 }
527 break;
528 }
philipel5ef2bc12017-02-21 07:28:31 -0800529 case kSecondRampup:
stefandb752f92016-12-05 08:23:40 -0800530 if (bitrate_bps >= GetExpectedHighBitrate() && !suspended) {
stefan45b5fe52017-03-09 06:27:02 -0800531 if (report_perf_stats_) {
532 webrtc::test::PrintResult("ramp_up_down_up", GetModifierString(),
533 "second_rampup", now - state_start_ms_,
534 "ms", false);
535 ReportResult("ramp-up-down-up-average-network-latency",
536 send_transport_->GetAverageDelayMs(), "milliseconds");
537 }
philipel5ef2bc12017-02-21 07:28:31 -0800538 // Apply loss during the transition between states if FEC is enabled.
539 forward_transport_config_.loss_percent = loss_rates_[test_state_];
540 test_state_ = kTransitionToNextState;
541 next_state_ = kTestEnd;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000542 }
543 break;
philipel5ef2bc12017-02-21 07:28:31 -0800544 case kTestEnd:
545 observation_complete_.Set();
546 break;
547 case kTransitionToNextState:
548 if (!ExpectingFec() || GetFecBytes() > 0) {
549 test_state_ = next_state_;
550 forward_transport_config_.link_capacity_kbps = link_rates_[test_state_];
551 // No loss while ramping up and down as it may affect the BWE
552 // negatively, making the test flaky.
553 forward_transport_config_.loss_percent = 0;
554 state_start_ms_ = now;
555 interval_start_ms_ = now;
556 sent_bytes_ = 0;
557 send_transport_->SetConfig(forward_transport_config_);
558 }
559 break;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000560 }
561}
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +0000562
stefan4fbd1452015-09-28 03:57:14 -0700563class RampUpTest : public test::CallTest {
Erik Språng6b8d3552015-09-24 15:06:57 +0200564 public:
stefan4fbd1452015-09-28 03:57:14 -0700565 RampUpTest() {}
Erik Språng6b8d3552015-09-24 15:06:57 +0200566
stefan4fbd1452015-09-28 03:57:14 -0700567 virtual ~RampUpTest() {
stefanff483612015-12-21 03:14:00 -0800568 EXPECT_EQ(nullptr, video_send_stream_);
569 EXPECT_TRUE(video_receive_streams_.empty());
Erik Språng6b8d3552015-09-24 15:06:57 +0200570 }
Erik Språng6b8d3552015-09-24 15:06:57 +0200571};
572
Stefan Holmerff2a6352016-01-14 10:00:21 +0100573static const uint32_t kStartBitrateBps = 60000;
574
stefan38d8b3c2017-01-09 04:19:24 -0800575TEST_F(RampUpTest, UpDownUpAbsSendTimeSimulcastRedRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800576 std::vector<int> loss_rates = {0, 0, 0, 0};
577 RampUpDownUpTester test(3, 0, 0, kStartBitrateBps,
stefan45b5fe52017-03-09 06:27:02 -0800578 RtpExtension::kAbsSendTimeUri, true, true, loss_rates,
579 true);
stefane74eef12016-01-08 06:47:13 -0800580 RunBaseTest(&test);
Shao Changbine62202f2015-04-21 20:24:50 +0800581}
Stefan Holmerff2a6352016-01-14 10:00:21 +0100582
Taylor Brandstetterba6b5032018-02-16 09:59:56 -0800583// TODO(bugs.webrtc.org/8878)
584#if defined(WEBRTC_MAC)
585#define MAYBE_UpDownUpTransportSequenceNumberRtx \
586 DISABLED_UpDownUpTransportSequenceNumberRtx
587#else
588#define MAYBE_UpDownUpTransportSequenceNumberRtx \
589 UpDownUpTransportSequenceNumberRtx
590#endif
591TEST_F(RampUpTest, MAYBE_UpDownUpTransportSequenceNumberRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800592 std::vector<int> loss_rates = {0, 0, 0, 0};
593 RampUpDownUpTester test(3, 0, 0, kStartBitrateBps,
isheriff6f8d6862016-05-26 11:24:55 -0700594 RtpExtension::kTransportSequenceNumberUri, true,
stefan45b5fe52017-03-09 06:27:02 -0800595 false, loss_rates, true);
philipel5ef2bc12017-02-21 07:28:31 -0800596 RunBaseTest(&test);
597}
598
stefan45b5fe52017-03-09 06:27:02 -0800599// TODO(holmer): Tests which don't report perf stats should be moved to a
600// different executable since they per definition are not perf tests.
Taylor Brandstetter05d98222017-10-10 12:12:53 -0700601// This test is disabled because it crashes on Linux, and is flaky on other
602// platforms. See: crbug.com/webrtc/7919
603TEST_F(RampUpTest, DISABLED_UpDownUpTransportSequenceNumberPacketLoss) {
philipel5ef2bc12017-02-21 07:28:31 -0800604 std::vector<int> loss_rates = {20, 0, 0, 0};
605 RampUpDownUpTester test(1, 0, 1, kStartBitrateBps,
606 RtpExtension::kTransportSequenceNumberUri, true,
stefan45b5fe52017-03-09 06:27:02 -0800607 false, loss_rates, false);
Stefan Holmerff2a6352016-01-14 10:00:21 +0100608 RunBaseTest(&test);
609}
610
Taylor Brandstetterab86e7f2018-02-12 15:16:02 -0800611// TODO(bugs.webrtc.org/8878)
612#if defined(WEBRTC_MAC)
613#define MAYBE_UpDownUpAudioVideoTransportSequenceNumberRtx \
614 DISABLED_UpDownUpAudioVideoTransportSequenceNumberRtx
615#else
616#define MAYBE_UpDownUpAudioVideoTransportSequenceNumberRtx \
617 UpDownUpAudioVideoTransportSequenceNumberRtx
618#endif
619TEST_F(RampUpTest, MAYBE_UpDownUpAudioVideoTransportSequenceNumberRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800620 std::vector<int> loss_rates = {0, 0, 0, 0};
621 RampUpDownUpTester test(3, 1, 0, kStartBitrateBps,
isheriff6f8d6862016-05-26 11:24:55 -0700622 RtpExtension::kTransportSequenceNumberUri, true,
stefanff2ebf52017-03-13 01:27:03 -0700623 false, loss_rates, false);
Stefan Holmerff2a6352016-01-14 10:00:21 +0100624 RunBaseTest(&test);
625}
626
stefan38d8b3c2017-01-09 04:19:24 -0800627TEST_F(RampUpTest, UpDownUpAudioTransportSequenceNumberRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800628 std::vector<int> loss_rates = {0, 0, 0, 0};
629 RampUpDownUpTester test(0, 1, 0, kStartBitrateBps,
mflodman86cc6ff2016-07-26 04:44:06 -0700630 RtpExtension::kTransportSequenceNumberUri, true,
stefanff2ebf52017-03-13 01:27:03 -0700631 false, loss_rates, false);
mflodman86cc6ff2016-07-26 04:44:06 -0700632 RunBaseTest(&test);
633}
634
stefan38d8b3c2017-01-09 04:19:24 -0800635TEST_F(RampUpTest, TOffsetSimulcastRedRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800636 RampUpTester test(3, 0, 0, 0, 0, RtpExtension::kTimestampOffsetUri, true,
637 true, true);
stefan38d8b3c2017-01-09 04:19:24 -0800638 RunBaseTest(&test);
639}
640
641TEST_F(RampUpTest, AbsSendTime) {
philipel5ef2bc12017-02-21 07:28:31 -0800642 RampUpTester test(1, 0, 0, 0, 0, RtpExtension::kAbsSendTimeUri, false, false,
stefanff2ebf52017-03-13 01:27:03 -0700643 false);
stefane74eef12016-01-08 06:47:13 -0800644 RunBaseTest(&test);
pbos@webrtc.org85bd53e2014-12-10 10:36:20 +0000645}
646
stefan38d8b3c2017-01-09 04:19:24 -0800647TEST_F(RampUpTest, AbsSendTimeSimulcastRedRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800648 RampUpTester test(3, 0, 0, 0, 0, RtpExtension::kAbsSendTimeUri, true, true,
stefan5a2c5062017-01-27 06:43:18 -0800649 true);
stefane74eef12016-01-08 06:47:13 -0800650 RunBaseTest(&test);
pbos@webrtc.org85bd53e2014-12-10 10:36:20 +0000651}
652
stefan38d8b3c2017-01-09 04:19:24 -0800653TEST_F(RampUpTest, TransportSequenceNumber) {
philipel5ef2bc12017-02-21 07:28:31 -0800654 RampUpTester test(1, 0, 0, 0, 0, RtpExtension::kTransportSequenceNumberUri,
stefanff2ebf52017-03-13 01:27:03 -0700655 false, false, false);
stefane74eef12016-01-08 06:47:13 -0800656 RunBaseTest(&test);
Erik Språng6b8d3552015-09-24 15:06:57 +0200657}
658
659TEST_F(RampUpTest, TransportSequenceNumberSimulcast) {
philipel5ef2bc12017-02-21 07:28:31 -0800660 RampUpTester test(3, 0, 0, 0, 0, RtpExtension::kTransportSequenceNumberUri,
stefanff2ebf52017-03-13 01:27:03 -0700661 false, false, false);
stefane74eef12016-01-08 06:47:13 -0800662 RunBaseTest(&test);
Erik Språng6b8d3552015-09-24 15:06:57 +0200663}
664
stefan38d8b3c2017-01-09 04:19:24 -0800665TEST_F(RampUpTest, TransportSequenceNumberSimulcastRedRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800666 RampUpTester test(3, 0, 0, 0, 0, RtpExtension::kTransportSequenceNumberUri,
stefan5a2c5062017-01-27 06:43:18 -0800667 true, true, true);
668 RunBaseTest(&test);
669}
670
Taylor Brandstetterab86e7f2018-02-12 15:16:02 -0800671// TODO(bugs.webrtc.org/8878)
672#if defined(WEBRTC_MAC)
673#define MAYBE_AudioTransportSequenceNumber DISABLED_AudioTransportSequenceNumber
674#else
675#define MAYBE_AudioTransportSequenceNumber AudioTransportSequenceNumber
676#endif
677TEST_F(RampUpTest, MAYBE_AudioTransportSequenceNumber) {
philipel5ef2bc12017-02-21 07:28:31 -0800678 RampUpTester test(0, 1, 0, 300000, 10000,
stefan5a2c5062017-01-27 06:43:18 -0800679 RtpExtension::kTransportSequenceNumberUri, false, false,
680 false);
stefane74eef12016-01-08 06:47:13 -0800681 RunBaseTest(&test);
Erik Språng6b8d3552015-09-24 15:06:57 +0200682}
pbos@webrtc.org744fbc72013-09-10 09:26:25 +0000683} // namespace webrtc