blob: 21caf175c8fb8a1cd7ace5a4ade74e41d10fe6cd [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
Artem Titov4e199e92018-08-20 13:30:39 +020013#include "call/fake_network_pipe.h"
14#include "call/simulated_network.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "rtc_base/checks.h"
16#include "rtc_base/logging.h"
17#include "rtc_base/platform_thread.h"
Jonas Olsson0a713b62018-04-04 15:49:32 +020018#include "rtc_base/stringencode.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "test/encoder_settings.h"
20#include "test/gtest.h"
21#include "test/testsupport/perf_test.h"
pbos@webrtc.org744fbc72013-09-10 09:26:25 +000022
23namespace webrtc {
pbos@webrtc.org29023282013-09-11 10:14:56 +000024namespace {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000025
Stefan Holmer723dff12015-10-05 14:59:41 +020026static const int64_t kPollIntervalMs = 20;
philipel5ef2bc12017-02-21 07:28:31 -080027static const int kExpectedHighVideoBitrateBps = 80000;
stefandb752f92016-12-05 08:23:40 -080028static const int kExpectedHighAudioBitrateBps = 30000;
29static const int kLowBandwidthLimitBps = 20000;
Sebastian Jansson12fb1702018-02-23 11:34:18 +010030// Set target detected bitrate to slightly larger than the target bitrate to
31// avoid flakiness.
32static const int kLowBitrateMarginBps = 2000;
pbos@webrtc.org29023282013-09-11 10:14:56 +000033
stefanff483612015-12-21 03:14:00 -080034std::vector<uint32_t> GenerateSsrcs(size_t num_streams, uint32_t ssrc_offset) {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000035 std::vector<uint32_t> ssrcs;
36 for (size_t i = 0; i != num_streams; ++i)
37 ssrcs.push_back(static_cast<uint32_t>(ssrc_offset + i));
38 return ssrcs;
39}
mflodman@webrtc.orgeb16b812014-06-16 08:57:39 +000040} // namespace
henrik.lundin@webrtc.org845862f2014-03-06 07:19:28 +000041
stefanff483612015-12-21 03:14:00 -080042RampUpTester::RampUpTester(size_t num_video_streams,
43 size_t num_audio_streams,
philipel5ef2bc12017-02-21 07:28:31 -080044 size_t num_flexfec_streams,
stefan4fbd1452015-09-28 03:57:14 -070045 unsigned int start_bitrate_bps,
stefan5a2c5062017-01-27 06:43:18 -080046 int64_t min_run_time_ms,
stefan4fbd1452015-09-28 03:57:14 -070047 const std::string& extension_type,
48 bool rtx,
stefan5a2c5062017-01-27 06:43:18 -080049 bool red,
50 bool report_perf_stats)
stefan4fbd1452015-09-28 03:57:14 -070051 : EndToEndTest(test::CallTest::kLongTimeoutMs),
tommi0f8b4032017-02-22 11:22:05 -080052 stop_event_(false, false),
stefan4fbd1452015-09-28 03:57:14 -070053 clock_(Clock::GetRealTimeClock()),
stefanff483612015-12-21 03:14:00 -080054 num_video_streams_(num_video_streams),
55 num_audio_streams_(num_audio_streams),
philipel5ef2bc12017-02-21 07:28:31 -080056 num_flexfec_streams_(num_flexfec_streams),
stefan4fbd1452015-09-28 03:57:14 -070057 rtx_(rtx),
58 red_(red),
stefan45b5fe52017-03-09 06:27:02 -080059 report_perf_stats_(report_perf_stats),
mflodman86cc6ff2016-07-26 04:44:06 -070060 sender_call_(nullptr),
stefan4fbd1452015-09-28 03:57:14 -070061 send_stream_(nullptr),
sprang4847ae62017-06-27 07:06:52 -070062 send_transport_(nullptr),
stefan4fbd1452015-09-28 03:57:14 -070063 start_bitrate_bps_(start_bitrate_bps),
stefan5a2c5062017-01-27 06:43:18 -080064 min_run_time_ms_(min_run_time_ms),
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000065 expected_bitrate_bps_(0),
Erik Språngf3a7c9d2015-10-05 14:03:22 +020066 test_start_ms_(-1),
stefan4fbd1452015-09-28 03:57:14 -070067 ramp_up_finished_ms_(-1),
68 extension_type_(extension_type),
stefanff483612015-12-21 03:14:00 -080069 video_ssrcs_(GenerateSsrcs(num_video_streams_, 100)),
70 video_rtx_ssrcs_(GenerateSsrcs(num_video_streams_, 200)),
71 audio_ssrcs_(GenerateSsrcs(num_audio_streams_, 300)),
Peter Boström8c38e8b2015-11-26 17:45:47 +010072 poller_thread_(&BitrateStatsPollingThread,
73 this,
mflodman86cc6ff2016-07-26 04:44:06 -070074 "BitrateStatsPollingThread") {
philipel5ef2bc12017-02-21 07:28:31 -080075 if (red_)
76 EXPECT_EQ(0u, num_flexfec_streams_);
Stefan Holmerff2a6352016-01-14 10:00:21 +010077 EXPECT_LE(num_audio_streams_, 1u);
stefan4fbd1452015-09-28 03:57:14 -070078}
79
Yves Gerey665174f2018-06-19 15:03:05 +020080RampUpTester::~RampUpTester() {}
stefan4fbd1452015-09-28 03:57:14 -070081
Sebastian Jansson72582242018-07-13 13:19:42 +020082void RampUpTester::ModifySenderCallConfig(Call::Config* config) {
stefan4fbd1452015-09-28 03:57:14 -070083 if (start_bitrate_bps_ != 0) {
Sebastian Jansson72582242018-07-13 13:19:42 +020084 config->bitrate_config.start_bitrate_bps = start_bitrate_bps_;
stefan4fbd1452015-09-28 03:57:14 -070085 }
Sebastian Jansson72582242018-07-13 13:19:42 +020086 config->bitrate_config.min_bitrate_bps = 10000;
stefan4fbd1452015-09-28 03:57:14 -070087}
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,
Artem Titov4e199e92018-08-20 13:30:39 +0200100 test::CallTest::payload_type_map_,
101 absl::make_unique<FakeNetworkPipe>(
102 Clock::GetRealTimeClock(),
103 absl::make_unique<SimulatedNetwork>(forward_transport_config_)));
stefane74eef12016-01-08 06:47:13 -0800104 return send_transport_;
stefanf116bd02015-10-27 08:29:42 -0700105}
106
Stefan Holmerd20e6512016-01-12 15:51:22 +0100107size_t RampUpTester::GetNumVideoStreams() const {
108 return num_video_streams_;
109}
110
Stefan Holmerff2a6352016-01-14 10:00:21 +0100111size_t RampUpTester::GetNumAudioStreams() const {
112 return num_audio_streams_;
113}
114
philipel5ef2bc12017-02-21 07:28:31 -0800115size_t RampUpTester::GetNumFlexfecStreams() const {
116 return num_flexfec_streams_;
117}
118
perkjfa10b552016-10-02 23:45:26 -0700119class RampUpTester::VideoStreamFactory
120 : public VideoEncoderConfig::VideoStreamFactoryInterface {
121 public:
122 VideoStreamFactory() {}
123
124 private:
125 std::vector<VideoStream> CreateEncoderStreams(
126 int width,
127 int height,
128 const VideoEncoderConfig& encoder_config) override {
129 std::vector<VideoStream> streams =
130 test::CreateVideoStreams(width, height, encoder_config);
131 if (encoder_config.number_of_streams == 1) {
132 streams[0].target_bitrate_bps = streams[0].max_bitrate_bps = 2000000;
133 }
134 return streams;
135 }
136};
137
stefanff483612015-12-21 03:14:00 -0800138void RampUpTester::ModifyVideoConfigs(
stefan4fbd1452015-09-28 03:57:14 -0700139 VideoSendStream::Config* send_config,
140 std::vector<VideoReceiveStream::Config>* receive_configs,
141 VideoEncoderConfig* encoder_config) {
142 send_config->suspend_below_min_bitrate = true;
perkjfa10b552016-10-02 23:45:26 -0700143 encoder_config->number_of_streams = num_video_streams_;
144 encoder_config->max_bitrate_bps = 2000000;
145 encoder_config->video_stream_factory =
146 new rtc::RefCountedObject<RampUpTester::VideoStreamFactory>();
stefanff483612015-12-21 03:14:00 -0800147 if (num_video_streams_ == 1) {
stefan4fbd1452015-09-28 03:57:14 -0700148 // For single stream rampup until 1mbps
149 expected_bitrate_bps_ = kSingleStreamTargetBps;
150 } else {
151 // For multi stream rampup until all streams are being sent. That means
perkjfa10b552016-10-02 23:45:26 -0700152 // enough bitrate to send all the target streams plus the min bitrate of
stefan4fbd1452015-09-28 03:57:14 -0700153 // the last one.
perkjfa10b552016-10-02 23:45:26 -0700154 std::vector<VideoStream> streams = test::CreateVideoStreams(
155 test::CallTest::kDefaultWidth, test::CallTest::kDefaultHeight,
156 *encoder_config);
157 expected_bitrate_bps_ = streams.back().min_bitrate_bps;
158 for (size_t i = 0; i < streams.size() - 1; ++i) {
159 expected_bitrate_bps_ += streams[i].target_bitrate_bps;
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000160 }
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000161 }
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000162
stefan4fbd1452015-09-28 03:57:14 -0700163 send_config->rtp.extensions.clear();
164
165 bool remb;
stefan43edf0f2015-11-20 18:05:48 -0800166 bool transport_cc;
isheriff6f8d6862016-05-26 11:24:55 -0700167 if (extension_type_ == RtpExtension::kAbsSendTimeUri) {
stefan4fbd1452015-09-28 03:57:14 -0700168 remb = true;
stefan43edf0f2015-11-20 18:05:48 -0800169 transport_cc = false;
stefan4fbd1452015-09-28 03:57:14 -0700170 send_config->rtp.extensions.push_back(
171 RtpExtension(extension_type_.c_str(), kAbsSendTimeExtensionId));
isheriff6f8d6862016-05-26 11:24:55 -0700172 } else if (extension_type_ == RtpExtension::kTransportSequenceNumberUri) {
stefan4fbd1452015-09-28 03:57:14 -0700173 remb = false;
stefan43edf0f2015-11-20 18:05:48 -0800174 transport_cc = true;
stefan4fbd1452015-09-28 03:57:14 -0700175 send_config->rtp.extensions.push_back(RtpExtension(
176 extension_type_.c_str(), kTransportSequenceNumberExtensionId));
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000177 } else {
stefan4fbd1452015-09-28 03:57:14 -0700178 remb = true;
stefan43edf0f2015-11-20 18:05:48 -0800179 transport_cc = false;
stefan4fbd1452015-09-28 03:57:14 -0700180 send_config->rtp.extensions.push_back(RtpExtension(
181 extension_type_.c_str(), kTransmissionTimeOffsetExtensionId));
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000182 }
stefan4fbd1452015-09-28 03:57:14 -0700183
184 send_config->rtp.nack.rtp_history_ms = test::CallTest::kNackRtpHistoryMs;
stefanff483612015-12-21 03:14:00 -0800185 send_config->rtp.ssrcs = video_ssrcs_;
stefan4fbd1452015-09-28 03:57:14 -0700186 if (rtx_) {
187 send_config->rtp.rtx.payload_type = test::CallTest::kSendRtxPayloadType;
stefanff483612015-12-21 03:14:00 -0800188 send_config->rtp.rtx.ssrcs = video_rtx_ssrcs_;
stefan4fbd1452015-09-28 03:57:14 -0700189 }
190 if (red_) {
brandtrb5f2c3f2016-10-04 23:28:39 -0700191 send_config->rtp.ulpfec.ulpfec_payload_type =
stefan4fbd1452015-09-28 03:57:14 -0700192 test::CallTest::kUlpfecPayloadType;
brandtrb5f2c3f2016-10-04 23:28:39 -0700193 send_config->rtp.ulpfec.red_payload_type = test::CallTest::kRedPayloadType;
brandtrfbfb5362016-11-17 04:18:37 -0800194 if (rtx_) {
195 send_config->rtp.ulpfec.red_rtx_payload_type =
196 test::CallTest::kRtxRedPayloadType;
197 }
stefan4fbd1452015-09-28 03:57:14 -0700198 }
199
200 size_t i = 0;
201 for (VideoReceiveStream::Config& recv_config : *receive_configs) {
202 recv_config.rtp.remb = remb;
stefan43edf0f2015-11-20 18:05:48 -0800203 recv_config.rtp.transport_cc = transport_cc;
stefan4fbd1452015-09-28 03:57:14 -0700204 recv_config.rtp.extensions = send_config->rtp.extensions;
205
stefanff483612015-12-21 03:14:00 -0800206 recv_config.rtp.remote_ssrc = video_ssrcs_[i];
stefan4fbd1452015-09-28 03:57:14 -0700207 recv_config.rtp.nack.rtp_history_ms = send_config->rtp.nack.rtp_history_ms;
208
209 if (red_) {
nisse3b3622f2017-09-26 02:49:21 -0700210 recv_config.rtp.red_payload_type =
brandtrb5f2c3f2016-10-04 23:28:39 -0700211 send_config->rtp.ulpfec.red_payload_type;
nisse3b3622f2017-09-26 02:49:21 -0700212 recv_config.rtp.ulpfec_payload_type =
brandtrb5f2c3f2016-10-04 23:28:39 -0700213 send_config->rtp.ulpfec.ulpfec_payload_type;
brandtrfbfb5362016-11-17 04:18:37 -0800214 if (rtx_) {
nisseca5706d2017-09-11 02:32:16 -0700215 recv_config.rtp.rtx_associated_payload_types
216 [send_config->rtp.ulpfec.red_rtx_payload_type] =
217 send_config->rtp.ulpfec.red_payload_type;
brandtrfbfb5362016-11-17 04:18:37 -0800218 }
stefan4fbd1452015-09-28 03:57:14 -0700219 }
220
221 if (rtx_) {
brandtr14742122017-01-27 04:53:07 -0800222 recv_config.rtp.rtx_ssrc = video_rtx_ssrcs_[i];
223 recv_config.rtp
nisse26e3abb2017-08-25 04:44:25 -0700224 .rtx_associated_payload_types[send_config->rtp.rtx.payload_type] =
Niels Möller259a4972018-04-05 15:36:51 +0200225 send_config->rtp.payload_type;
stefan4fbd1452015-09-28 03:57:14 -0700226 }
227 ++i;
228 }
philipel5ef2bc12017-02-21 07:28:31 -0800229
230 RTC_DCHECK_LE(num_flexfec_streams_, 1);
231 if (num_flexfec_streams_ == 1) {
232 send_config->rtp.flexfec.payload_type = test::CallTest::kFlexfecPayloadType;
233 send_config->rtp.flexfec.ssrc = test::CallTest::kFlexfecSendSsrc;
234 send_config->rtp.flexfec.protected_media_ssrcs = {video_ssrcs_[0]};
235 }
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000236}
237
Stefan Holmerff2a6352016-01-14 10:00:21 +0100238void RampUpTester::ModifyAudioConfigs(
239 AudioSendStream::Config* send_config,
240 std::vector<AudioReceiveStream::Config>* receive_configs) {
241 if (num_audio_streams_ == 0)
242 return;
243
isheriff6f8d6862016-05-26 11:24:55 -0700244 EXPECT_NE(RtpExtension::kTimestampOffsetUri, extension_type_)
Stefan Holmerff2a6352016-01-14 10:00:21 +0100245 << "Audio BWE not supported with toffset.";
philipel5ef2bc12017-02-21 07:28:31 -0800246 EXPECT_NE(RtpExtension::kAbsSendTimeUri, extension_type_)
247 << "Audio BWE not supported with abs-send-time.";
Stefan Holmerff2a6352016-01-14 10:00:21 +0100248
249 send_config->rtp.ssrc = audio_ssrcs_[0];
250 send_config->rtp.extensions.clear();
251
minyue10cbb462016-11-07 09:29:22 -0800252 send_config->min_bitrate_bps = 6000;
253 send_config->max_bitrate_bps = 60000;
mflodman86cc6ff2016-07-26 04:44:06 -0700254
Stefan Holmerff2a6352016-01-14 10:00:21 +0100255 bool transport_cc = false;
philipel5ef2bc12017-02-21 07:28:31 -0800256 if (extension_type_ == RtpExtension::kTransportSequenceNumberUri) {
Stefan Holmerff2a6352016-01-14 10:00:21 +0100257 transport_cc = true;
258 send_config->rtp.extensions.push_back(RtpExtension(
259 extension_type_.c_str(), kTransportSequenceNumberExtensionId));
260 }
261
262 for (AudioReceiveStream::Config& recv_config : *receive_configs) {
Stefan Holmerff2a6352016-01-14 10:00:21 +0100263 recv_config.rtp.transport_cc = transport_cc;
264 recv_config.rtp.extensions = send_config->rtp.extensions;
265 recv_config.rtp.remote_ssrc = send_config->rtp.ssrc;
266 }
267}
268
philipel5ef2bc12017-02-21 07:28:31 -0800269void RampUpTester::ModifyFlexfecConfigs(
270 std::vector<FlexfecReceiveStream::Config>* receive_configs) {
271 if (num_flexfec_streams_ == 0)
272 return;
273 RTC_DCHECK_EQ(1, num_flexfec_streams_);
274 (*receive_configs)[0].payload_type = test::CallTest::kFlexfecPayloadType;
275 (*receive_configs)[0].remote_ssrc = test::CallTest::kFlexfecSendSsrc;
276 (*receive_configs)[0].protected_media_ssrcs = {video_ssrcs_[0]};
277 (*receive_configs)[0].local_ssrc = video_ssrcs_[0];
278 if (extension_type_ == RtpExtension::kAbsSendTimeUri) {
279 (*receive_configs)[0].transport_cc = false;
280 (*receive_configs)[0].rtp_header_extensions.push_back(
281 RtpExtension(extension_type_.c_str(), kAbsSendTimeExtensionId));
282 } else if (extension_type_ == RtpExtension::kTransportSequenceNumberUri) {
283 (*receive_configs)[0].transport_cc = true;
284 (*receive_configs)[0].rtp_header_extensions.push_back(RtpExtension(
285 extension_type_.c_str(), kTransportSequenceNumberExtensionId));
286 }
287}
288
stefan4fbd1452015-09-28 03:57:14 -0700289void RampUpTester::OnCallsCreated(Call* sender_call, Call* receiver_call) {
290 sender_call_ = sender_call;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000291}
292
tommi0f8b4032017-02-22 11:22:05 -0800293void RampUpTester::BitrateStatsPollingThread(void* obj) {
294 static_cast<RampUpTester*>(obj)->PollStats();
pbos@webrtc.org32452b22014-10-22 12:15:24 +0000295}
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000296
tommi0f8b4032017-02-22 11:22:05 -0800297void RampUpTester::PollStats() {
298 do {
299 if (sender_call_) {
300 Call::Stats stats = sender_call_->GetStats();
stefan4fbd1452015-09-28 03:57:14 -0700301
tommi0f8b4032017-02-22 11:22:05 -0800302 EXPECT_GE(stats.send_bandwidth_bps, start_bitrate_bps_);
303 EXPECT_GE(expected_bitrate_bps_, 0);
304 if (stats.send_bandwidth_bps >= expected_bitrate_bps_ &&
305 (min_run_time_ms_ == -1 ||
306 clock_->TimeInMilliseconds() - test_start_ms_ >= min_run_time_ms_)) {
307 ramp_up_finished_ms_ = clock_->TimeInMilliseconds();
308 observation_complete_.Set();
309 }
stefan4fbd1452015-09-28 03:57:14 -0700310 }
tommi0f8b4032017-02-22 11:22:05 -0800311 } while (!stop_event_.Wait(kPollIntervalMs));
Erik Språng468e62a2015-07-06 10:50:47 +0200312}
313
stefan4fbd1452015-09-28 03:57:14 -0700314void RampUpTester::ReportResult(const std::string& measurement,
315 size_t value,
316 const std::string& units) const {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000317 webrtc::test::PrintResult(
318 measurement, "",
stefanff483612015-12-21 03:14:00 -0800319 ::testing::UnitTest::GetInstance()->current_test_info()->name(), value,
320 units, false);
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000321}
322
stefan092508a2015-09-29 02:26:42 -0700323void RampUpTester::AccumulateStats(const VideoSendStream::StreamStats& stream,
324 size_t* total_packets_sent,
325 size_t* total_sent,
326 size_t* padding_sent,
327 size_t* media_sent) const {
stefan4fbd1452015-09-28 03:57:14 -0700328 *total_packets_sent += stream.rtp_stats.transmitted.packets +
329 stream.rtp_stats.retransmitted.packets +
330 stream.rtp_stats.fec.packets;
331 *total_sent += stream.rtp_stats.transmitted.TotalBytes() +
332 stream.rtp_stats.retransmitted.TotalBytes() +
333 stream.rtp_stats.fec.TotalBytes();
334 *padding_sent += stream.rtp_stats.transmitted.padding_bytes +
335 stream.rtp_stats.retransmitted.padding_bytes +
336 stream.rtp_stats.fec.padding_bytes;
337 *media_sent += stream.rtp_stats.MediaPayloadBytes();
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000338}
339
stefan4fbd1452015-09-28 03:57:14 -0700340void RampUpTester::TriggerTestDone() {
Erik Språngf3a7c9d2015-10-05 14:03:22 +0200341 RTC_DCHECK_GE(test_start_ms_, 0);
342
Stefan Holmerff2a6352016-01-14 10:00:21 +0100343 // TODO(holmer): Add audio send stats here too when those APIs are available.
mflodman86cc6ff2016-07-26 04:44:06 -0700344 if (!send_stream_)
345 return;
346
stefan4fbd1452015-09-28 03:57:14 -0700347 VideoSendStream::Stats send_stats = send_stream_->GetStats();
348
349 size_t total_packets_sent = 0;
350 size_t total_sent = 0;
351 size_t padding_sent = 0;
352 size_t media_sent = 0;
stefanff483612015-12-21 03:14:00 -0800353 for (uint32_t ssrc : video_ssrcs_) {
stefan092508a2015-09-29 02:26:42 -0700354 AccumulateStats(send_stats.substreams[ssrc], &total_packets_sent,
355 &total_sent, &padding_sent, &media_sent);
stefan4fbd1452015-09-28 03:57:14 -0700356 }
357
358 size_t rtx_total_packets_sent = 0;
359 size_t rtx_total_sent = 0;
360 size_t rtx_padding_sent = 0;
361 size_t rtx_media_sent = 0;
stefanff483612015-12-21 03:14:00 -0800362 for (uint32_t rtx_ssrc : video_rtx_ssrcs_) {
stefan092508a2015-09-29 02:26:42 -0700363 AccumulateStats(send_stats.substreams[rtx_ssrc], &rtx_total_packets_sent,
364 &rtx_total_sent, &rtx_padding_sent, &rtx_media_sent);
stefan4fbd1452015-09-28 03:57:14 -0700365 }
366
stefan5a2c5062017-01-27 06:43:18 -0800367 if (report_perf_stats_) {
stefan5a2c5062017-01-27 06:43:18 -0800368 ReportResult("ramp-up-media-sent", media_sent, "bytes");
369 ReportResult("ramp-up-padding-sent", padding_sent, "bytes");
stefan5a2c5062017-01-27 06:43:18 -0800370 ReportResult("ramp-up-rtx-media-sent", rtx_media_sent, "bytes");
371 ReportResult("ramp-up-rtx-padding-sent", rtx_padding_sent, "bytes");
372 if (ramp_up_finished_ms_ >= 0) {
373 ReportResult("ramp-up-time", ramp_up_finished_ms_ - test_start_ms_,
374 "milliseconds");
375 }
376 ReportResult("ramp-up-average-network-latency",
377 send_transport_->GetAverageDelayMs(), "milliseconds");
stefan4fbd1452015-09-28 03:57:14 -0700378 }
379}
380
381void RampUpTester::PerformTest() {
Erik Språngf3a7c9d2015-10-05 14:03:22 +0200382 test_start_ms_ = clock_->TimeInMilliseconds();
Peter Boström8c38e8b2015-11-26 17:45:47 +0100383 poller_thread_.Start();
Peter Boström5811a392015-12-10 13:02:50 +0100384 EXPECT_TRUE(Wait()) << "Timed out while waiting for ramp-up to complete.";
stefan4fbd1452015-09-28 03:57:14 -0700385 TriggerTestDone();
tommi0f8b4032017-02-22 11:22:05 -0800386 stop_event_.Set();
Peter Boström8c38e8b2015-11-26 17:45:47 +0100387 poller_thread_.Stop();
stefan4fbd1452015-09-28 03:57:14 -0700388}
389
Stefan Holmerff2a6352016-01-14 10:00:21 +0100390RampUpDownUpTester::RampUpDownUpTester(size_t num_video_streams,
391 size_t num_audio_streams,
philipel5ef2bc12017-02-21 07:28:31 -0800392 size_t num_flexfec_streams,
stefan4fbd1452015-09-28 03:57:14 -0700393 unsigned int start_bitrate_bps,
394 const std::string& extension_type,
395 bool rtx,
philipel5ef2bc12017-02-21 07:28:31 -0800396 bool red,
stefan45b5fe52017-03-09 06:27:02 -0800397 const std::vector<int>& loss_rates,
398 bool report_perf_stats)
Stefan Holmerff2a6352016-01-14 10:00:21 +0100399 : RampUpTester(num_video_streams,
400 num_audio_streams,
philipel5ef2bc12017-02-21 07:28:31 -0800401 num_flexfec_streams,
Stefan Holmerff2a6352016-01-14 10:00:21 +0100402 start_bitrate_bps,
stefan5a2c5062017-01-27 06:43:18 -0800403 0,
Stefan Holmerff2a6352016-01-14 10:00:21 +0100404 extension_type,
405 rtx,
stefan5a2c5062017-01-27 06:43:18 -0800406 red,
stefan45b5fe52017-03-09 06:27:02 -0800407 report_perf_stats),
stefan76d9c9c2017-04-01 06:51:09 -0700408 link_rates_({4 * GetExpectedHighBitrate() / (3 * 1000),
409 kLowBandwidthLimitBps / 1000,
410 4 * GetExpectedHighBitrate() / (3 * 1000), 0}),
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000411 test_state_(kFirstRampup),
philipel5ef2bc12017-02-21 07:28:31 -0800412 next_state_(kTransitionToNextState),
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000413 state_start_ms_(clock_->TimeInMilliseconds()),
stefan4fbd1452015-09-28 03:57:14 -0700414 interval_start_ms_(clock_->TimeInMilliseconds()),
philipel5ef2bc12017-02-21 07:28:31 -0800415 sent_bytes_(0),
416 loss_rates_(loss_rates) {
417 forward_transport_config_.link_capacity_kbps = link_rates_[test_state_];
418 forward_transport_config_.queue_delay_ms = 100;
419 forward_transport_config_.loss_percent = loss_rates_[test_state_];
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000420}
421
stefan4fbd1452015-09-28 03:57:14 -0700422RampUpDownUpTester::~RampUpDownUpTester() {}
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000423
tommi0f8b4032017-02-22 11:22:05 -0800424void RampUpDownUpTester::PollStats() {
425 do {
Alex Narest78609d52017-10-20 10:37:47 +0200426 int transmit_bitrate_bps = 0;
427 bool suspended = false;
428 if (num_video_streams_ > 0) {
tommi0f8b4032017-02-22 11:22:05 -0800429 webrtc::VideoSendStream::Stats stats = send_stream_->GetStats();
tommi0f8b4032017-02-22 11:22:05 -0800430 for (auto it : stats.substreams) {
431 transmit_bitrate_bps += it.second.total_bitrate_bps;
432 }
Alex Narest78609d52017-10-20 10:37:47 +0200433 suspended = stats.suspended;
434 }
435 if (num_audio_streams_ > 0 && sender_call_ != nullptr) {
tommi0f8b4032017-02-22 11:22:05 -0800436 // An audio send stream doesn't have bitrate stats, so the call send BW is
437 // currently used instead.
Alex Narest78609d52017-10-20 10:37:47 +0200438 transmit_bitrate_bps = sender_call_->GetStats().send_bandwidth_bps;
mflodman@webrtc.orgeb16b812014-06-16 08:57:39 +0000439 }
Alex Narest78609d52017-10-20 10:37:47 +0200440 EvolveTestState(transmit_bitrate_bps, suspended);
tommi0f8b4032017-02-22 11:22:05 -0800441 } while (!stop_event_.Wait(kPollIntervalMs));
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000442}
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000443
Sebastian Jansson72582242018-07-13 13:19:42 +0200444void RampUpDownUpTester::ModifyReceiverCallConfig(Call::Config* config) {
445 config->bitrate_config.min_bitrate_bps = 10000;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000446}
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000447
stefan4fbd1452015-09-28 03:57:14 -0700448std::string RampUpDownUpTester::GetModifierString() const {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000449 std::string str("_");
stefanff483612015-12-21 03:14:00 -0800450 if (num_video_streams_ > 0) {
Jonas Olsson0a713b62018-04-04 15:49:32 +0200451 str += rtc::ToString(num_video_streams_);
stefanff483612015-12-21 03:14:00 -0800452 str += "stream";
453 str += (num_video_streams_ > 1 ? "s" : "");
454 str += "_";
455 }
456 if (num_audio_streams_ > 0) {
Jonas Olsson0a713b62018-04-04 15:49:32 +0200457 str += rtc::ToString(num_audio_streams_);
stefanff483612015-12-21 03:14:00 -0800458 str += "stream";
459 str += (num_audio_streams_ > 1 ? "s" : "");
460 str += "_";
461 }
stefan4fbd1452015-09-28 03:57:14 -0700462 str += (rtx_ ? "" : "no");
Edward Lemurdd3987f2018-01-04 19:44:54 +0100463 str += "rtx_";
464 str += (red_ ? "" : "no");
465 str += "red";
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000466 return str;
467}
andresp@webrtc.orgc1480792014-03-20 03:23:55 +0000468
stefandb752f92016-12-05 08:23:40 -0800469int RampUpDownUpTester::GetExpectedHighBitrate() const {
stefan38d8b3c2017-01-09 04:19:24 -0800470 int expected_bitrate_bps = 0;
471 if (num_audio_streams_ > 0)
472 expected_bitrate_bps += kExpectedHighAudioBitrateBps;
473 if (num_video_streams_ > 0)
474 expected_bitrate_bps += kExpectedHighVideoBitrateBps;
475 return expected_bitrate_bps;
476}
477
philipel5ef2bc12017-02-21 07:28:31 -0800478size_t RampUpDownUpTester::GetFecBytes() const {
479 size_t flex_fec_bytes = 0;
480 if (num_flexfec_streams_ > 0) {
481 webrtc::VideoSendStream::Stats stats = send_stream_->GetStats();
482 for (const auto& kv : stats.substreams)
483 flex_fec_bytes += kv.second.rtp_stats.fec.TotalBytes();
484 }
485 return flex_fec_bytes;
486}
487
488bool RampUpDownUpTester::ExpectingFec() const {
489 return num_flexfec_streams_ > 0 && forward_transport_config_.loss_percent > 0;
490}
491
stefan4fbd1452015-09-28 03:57:14 -0700492void RampUpDownUpTester::EvolveTestState(int bitrate_bps, bool suspended) {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000493 int64_t now = clock_->TimeInMilliseconds();
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000494 switch (test_state_) {
philipel5ef2bc12017-02-21 07:28:31 -0800495 case kFirstRampup:
stefan4fbd1452015-09-28 03:57:14 -0700496 EXPECT_FALSE(suspended);
stefandb752f92016-12-05 08:23:40 -0800497 if (bitrate_bps >= GetExpectedHighBitrate()) {
stefan45b5fe52017-03-09 06:27:02 -0800498 if (report_perf_stats_) {
499 webrtc::test::PrintResult("ramp_up_down_up", GetModifierString(),
500 "first_rampup", now - state_start_ms_, "ms",
501 false);
502 }
philipel5ef2bc12017-02-21 07:28:31 -0800503 // Apply loss during the transition between states if FEC is enabled.
504 forward_transport_config_.loss_percent = loss_rates_[test_state_];
505 test_state_ = kTransitionToNextState;
506 next_state_ = kLowRate;
andresp@webrtc.orgc1480792014-03-20 03:23:55 +0000507 }
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000508 break;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000509 case kLowRate: {
mflodman86cc6ff2016-07-26 04:44:06 -0700510 // Audio streams are never suspended.
511 bool check_suspend_state = num_video_streams_ > 0;
Sebastian Jansson12fb1702018-02-23 11:34:18 +0100512 if (bitrate_bps < kLowBandwidthLimitBps + kLowBitrateMarginBps &&
mflodman86cc6ff2016-07-26 04:44:06 -0700513 suspended == check_suspend_state) {
stefan45b5fe52017-03-09 06:27:02 -0800514 if (report_perf_stats_) {
515 webrtc::test::PrintResult("ramp_up_down_up", GetModifierString(),
516 "rampdown", now - state_start_ms_, "ms",
517 false);
518 }
philipel5ef2bc12017-02-21 07:28:31 -0800519 // Apply loss during the transition between states if FEC is enabled.
520 forward_transport_config_.loss_percent = loss_rates_[test_state_];
521 test_state_ = kTransitionToNextState;
522 next_state_ = kSecondRampup;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000523 }
524 break;
525 }
philipel5ef2bc12017-02-21 07:28:31 -0800526 case kSecondRampup:
stefandb752f92016-12-05 08:23:40 -0800527 if (bitrate_bps >= GetExpectedHighBitrate() && !suspended) {
stefan45b5fe52017-03-09 06:27:02 -0800528 if (report_perf_stats_) {
529 webrtc::test::PrintResult("ramp_up_down_up", GetModifierString(),
530 "second_rampup", now - state_start_ms_,
531 "ms", false);
532 ReportResult("ramp-up-down-up-average-network-latency",
533 send_transport_->GetAverageDelayMs(), "milliseconds");
534 }
philipel5ef2bc12017-02-21 07:28:31 -0800535 // Apply loss during the transition between states if FEC is enabled.
536 forward_transport_config_.loss_percent = loss_rates_[test_state_];
537 test_state_ = kTransitionToNextState;
538 next_state_ = kTestEnd;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000539 }
540 break;
philipel5ef2bc12017-02-21 07:28:31 -0800541 case kTestEnd:
542 observation_complete_.Set();
543 break;
544 case kTransitionToNextState:
545 if (!ExpectingFec() || GetFecBytes() > 0) {
546 test_state_ = next_state_;
547 forward_transport_config_.link_capacity_kbps = link_rates_[test_state_];
548 // No loss while ramping up and down as it may affect the BWE
549 // negatively, making the test flaky.
550 forward_transport_config_.loss_percent = 0;
551 state_start_ms_ = now;
552 interval_start_ms_ = now;
553 sent_bytes_ = 0;
554 send_transport_->SetConfig(forward_transport_config_);
555 }
556 break;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000557 }
558}
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +0000559
stefan4fbd1452015-09-28 03:57:14 -0700560class RampUpTest : public test::CallTest {
Erik Språng6b8d3552015-09-24 15:06:57 +0200561 public:
stefan4fbd1452015-09-28 03:57:14 -0700562 RampUpTest() {}
Erik Språng6b8d3552015-09-24 15:06:57 +0200563};
564
Stefan Holmerff2a6352016-01-14 10:00:21 +0100565static const uint32_t kStartBitrateBps = 60000;
566
stefan38d8b3c2017-01-09 04:19:24 -0800567TEST_F(RampUpTest, UpDownUpAbsSendTimeSimulcastRedRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800568 std::vector<int> loss_rates = {0, 0, 0, 0};
569 RampUpDownUpTester test(3, 0, 0, kStartBitrateBps,
stefan45b5fe52017-03-09 06:27:02 -0800570 RtpExtension::kAbsSendTimeUri, true, true, loss_rates,
571 true);
stefane74eef12016-01-08 06:47:13 -0800572 RunBaseTest(&test);
Shao Changbine62202f2015-04-21 20:24:50 +0800573}
Stefan Holmerff2a6352016-01-14 10:00:21 +0100574
Taylor Brandstetterba6b5032018-02-16 09:59:56 -0800575// TODO(bugs.webrtc.org/8878)
576#if defined(WEBRTC_MAC)
577#define MAYBE_UpDownUpTransportSequenceNumberRtx \
578 DISABLED_UpDownUpTransportSequenceNumberRtx
579#else
580#define MAYBE_UpDownUpTransportSequenceNumberRtx \
581 UpDownUpTransportSequenceNumberRtx
582#endif
583TEST_F(RampUpTest, MAYBE_UpDownUpTransportSequenceNumberRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800584 std::vector<int> loss_rates = {0, 0, 0, 0};
585 RampUpDownUpTester test(3, 0, 0, kStartBitrateBps,
isheriff6f8d6862016-05-26 11:24:55 -0700586 RtpExtension::kTransportSequenceNumberUri, true,
stefan45b5fe52017-03-09 06:27:02 -0800587 false, loss_rates, true);
philipel5ef2bc12017-02-21 07:28:31 -0800588 RunBaseTest(&test);
589}
590
stefan45b5fe52017-03-09 06:27:02 -0800591// TODO(holmer): Tests which don't report perf stats should be moved to a
592// different executable since they per definition are not perf tests.
Taylor Brandstetter05d98222017-10-10 12:12:53 -0700593// This test is disabled because it crashes on Linux, and is flaky on other
594// platforms. See: crbug.com/webrtc/7919
595TEST_F(RampUpTest, DISABLED_UpDownUpTransportSequenceNumberPacketLoss) {
philipel5ef2bc12017-02-21 07:28:31 -0800596 std::vector<int> loss_rates = {20, 0, 0, 0};
597 RampUpDownUpTester test(1, 0, 1, kStartBitrateBps,
598 RtpExtension::kTransportSequenceNumberUri, true,
stefan45b5fe52017-03-09 06:27:02 -0800599 false, loss_rates, false);
Stefan Holmerff2a6352016-01-14 10:00:21 +0100600 RunBaseTest(&test);
601}
602
Taylor Brandstetterab86e7f2018-02-12 15:16:02 -0800603// TODO(bugs.webrtc.org/8878)
604#if defined(WEBRTC_MAC)
605#define MAYBE_UpDownUpAudioVideoTransportSequenceNumberRtx \
606 DISABLED_UpDownUpAudioVideoTransportSequenceNumberRtx
607#else
608#define MAYBE_UpDownUpAudioVideoTransportSequenceNumberRtx \
609 UpDownUpAudioVideoTransportSequenceNumberRtx
610#endif
611TEST_F(RampUpTest, MAYBE_UpDownUpAudioVideoTransportSequenceNumberRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800612 std::vector<int> loss_rates = {0, 0, 0, 0};
613 RampUpDownUpTester test(3, 1, 0, kStartBitrateBps,
isheriff6f8d6862016-05-26 11:24:55 -0700614 RtpExtension::kTransportSequenceNumberUri, true,
stefanff2ebf52017-03-13 01:27:03 -0700615 false, loss_rates, false);
Stefan Holmerff2a6352016-01-14 10:00:21 +0100616 RunBaseTest(&test);
617}
618
stefan38d8b3c2017-01-09 04:19:24 -0800619TEST_F(RampUpTest, UpDownUpAudioTransportSequenceNumberRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800620 std::vector<int> loss_rates = {0, 0, 0, 0};
621 RampUpDownUpTester test(0, 1, 0, kStartBitrateBps,
mflodman86cc6ff2016-07-26 04:44:06 -0700622 RtpExtension::kTransportSequenceNumberUri, true,
stefanff2ebf52017-03-13 01:27:03 -0700623 false, loss_rates, false);
mflodman86cc6ff2016-07-26 04:44:06 -0700624 RunBaseTest(&test);
625}
626
stefan38d8b3c2017-01-09 04:19:24 -0800627TEST_F(RampUpTest, TOffsetSimulcastRedRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800628 RampUpTester test(3, 0, 0, 0, 0, RtpExtension::kTimestampOffsetUri, true,
629 true, true);
stefan38d8b3c2017-01-09 04:19:24 -0800630 RunBaseTest(&test);
631}
632
633TEST_F(RampUpTest, AbsSendTime) {
philipel5ef2bc12017-02-21 07:28:31 -0800634 RampUpTester test(1, 0, 0, 0, 0, RtpExtension::kAbsSendTimeUri, false, false,
stefanff2ebf52017-03-13 01:27:03 -0700635 false);
stefane74eef12016-01-08 06:47:13 -0800636 RunBaseTest(&test);
pbos@webrtc.org85bd53e2014-12-10 10:36:20 +0000637}
638
stefan38d8b3c2017-01-09 04:19:24 -0800639TEST_F(RampUpTest, AbsSendTimeSimulcastRedRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800640 RampUpTester test(3, 0, 0, 0, 0, RtpExtension::kAbsSendTimeUri, true, true,
stefan5a2c5062017-01-27 06:43:18 -0800641 true);
stefane74eef12016-01-08 06:47:13 -0800642 RunBaseTest(&test);
pbos@webrtc.org85bd53e2014-12-10 10:36:20 +0000643}
644
stefan38d8b3c2017-01-09 04:19:24 -0800645TEST_F(RampUpTest, TransportSequenceNumber) {
philipel5ef2bc12017-02-21 07:28:31 -0800646 RampUpTester test(1, 0, 0, 0, 0, RtpExtension::kTransportSequenceNumberUri,
stefanff2ebf52017-03-13 01:27:03 -0700647 false, false, false);
stefane74eef12016-01-08 06:47:13 -0800648 RunBaseTest(&test);
Erik Språng6b8d3552015-09-24 15:06:57 +0200649}
650
651TEST_F(RampUpTest, TransportSequenceNumberSimulcast) {
philipel5ef2bc12017-02-21 07:28:31 -0800652 RampUpTester test(3, 0, 0, 0, 0, RtpExtension::kTransportSequenceNumberUri,
stefanff2ebf52017-03-13 01:27:03 -0700653 false, false, false);
stefane74eef12016-01-08 06:47:13 -0800654 RunBaseTest(&test);
Erik Språng6b8d3552015-09-24 15:06:57 +0200655}
656
stefan38d8b3c2017-01-09 04:19:24 -0800657TEST_F(RampUpTest, TransportSequenceNumberSimulcastRedRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800658 RampUpTester test(3, 0, 0, 0, 0, RtpExtension::kTransportSequenceNumberUri,
stefan5a2c5062017-01-27 06:43:18 -0800659 true, true, true);
660 RunBaseTest(&test);
661}
662
Taylor Brandstetterab86e7f2018-02-12 15:16:02 -0800663// TODO(bugs.webrtc.org/8878)
664#if defined(WEBRTC_MAC)
665#define MAYBE_AudioTransportSequenceNumber DISABLED_AudioTransportSequenceNumber
666#else
667#define MAYBE_AudioTransportSequenceNumber AudioTransportSequenceNumber
668#endif
669TEST_F(RampUpTest, MAYBE_AudioTransportSequenceNumber) {
philipel5ef2bc12017-02-21 07:28:31 -0800670 RampUpTester test(0, 1, 0, 300000, 10000,
stefan5a2c5062017-01-27 06:43:18 -0800671 RtpExtension::kTransportSequenceNumberUri, false, false,
672 false);
stefane74eef12016-01-08 06:47:13 -0800673 RunBaseTest(&test);
Erik Språng6b8d3552015-09-24 15:06:57 +0200674}
pbos@webrtc.org744fbc72013-09-10 09:26:25 +0000675} // namespace webrtc