blob: 47cb7e484877159caede12b8376a10065065fa5c [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"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#include "rtc_base/checks.h"
15#include "rtc_base/logging.h"
16#include "rtc_base/platform_thread.h"
Jonas Olsson0a713b62018-04-04 15:49:32 +020017#include "rtc_base/stringencode.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "test/encoder_settings.h"
19#include "test/gtest.h"
20#include "test/testsupport/perf_test.h"
pbos@webrtc.org744fbc72013-09-10 09:26:25 +000021
22namespace webrtc {
pbos@webrtc.org29023282013-09-11 10:14:56 +000023namespace {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000024
Stefan Holmer723dff12015-10-05 14:59:41 +020025static const int64_t kPollIntervalMs = 20;
philipel5ef2bc12017-02-21 07:28:31 -080026static const int kExpectedHighVideoBitrateBps = 80000;
stefandb752f92016-12-05 08:23:40 -080027static const int kExpectedHighAudioBitrateBps = 30000;
28static const int kLowBandwidthLimitBps = 20000;
Sebastian Jansson12fb1702018-02-23 11:34:18 +010029// Set target detected bitrate to slightly larger than the target bitrate to
30// avoid flakiness.
31static const int kLowBitrateMarginBps = 2000;
pbos@webrtc.org29023282013-09-11 10:14:56 +000032
stefanff483612015-12-21 03:14:00 -080033std::vector<uint32_t> GenerateSsrcs(size_t num_streams, uint32_t ssrc_offset) {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000034 std::vector<uint32_t> ssrcs;
35 for (size_t i = 0; i != num_streams; ++i)
36 ssrcs.push_back(static_cast<uint32_t>(ssrc_offset + i));
37 return ssrcs;
38}
mflodman@webrtc.orgeb16b812014-06-16 08:57:39 +000039} // namespace
henrik.lundin@webrtc.org845862f2014-03-06 07:19:28 +000040
stefanff483612015-12-21 03:14:00 -080041RampUpTester::RampUpTester(size_t num_video_streams,
42 size_t num_audio_streams,
philipel5ef2bc12017-02-21 07:28:31 -080043 size_t num_flexfec_streams,
stefan4fbd1452015-09-28 03:57:14 -070044 unsigned int start_bitrate_bps,
stefan5a2c5062017-01-27 06:43:18 -080045 int64_t min_run_time_ms,
stefan4fbd1452015-09-28 03:57:14 -070046 const std::string& extension_type,
47 bool rtx,
stefan5a2c5062017-01-27 06:43:18 -080048 bool red,
49 bool report_perf_stats)
stefan4fbd1452015-09-28 03:57:14 -070050 : EndToEndTest(test::CallTest::kLongTimeoutMs),
tommi0f8b4032017-02-22 11:22:05 -080051 stop_event_(false, false),
stefan4fbd1452015-09-28 03:57:14 -070052 clock_(Clock::GetRealTimeClock()),
stefanff483612015-12-21 03:14:00 -080053 num_video_streams_(num_video_streams),
54 num_audio_streams_(num_audio_streams),
philipel5ef2bc12017-02-21 07:28:31 -080055 num_flexfec_streams_(num_flexfec_streams),
stefan4fbd1452015-09-28 03:57:14 -070056 rtx_(rtx),
57 red_(red),
stefan45b5fe52017-03-09 06:27:02 -080058 report_perf_stats_(report_perf_stats),
mflodman86cc6ff2016-07-26 04:44:06 -070059 sender_call_(nullptr),
stefan4fbd1452015-09-28 03:57:14 -070060 send_stream_(nullptr),
sprang4847ae62017-06-27 07:06:52 -070061 send_transport_(nullptr),
Artem Titov631cafa2018-08-21 21:01:00 +020062 send_simulated_network_(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) {
Artem Titov631cafa2018-08-21 21:01:00 +020098 auto network = absl::make_unique<SimulatedNetwork>(forward_transport_config_);
99 send_simulated_network_ = network.get();
minyue20c84cc2017-04-10 16:57:57 -0700100 send_transport_ = new test::PacketTransport(
eladalon413ee9a2017-08-22 04:02:52 -0700101 task_queue, sender_call, this, test::PacketTransport::kSender,
Artem Titov4e199e92018-08-20 13:30:39 +0200102 test::CallTest::payload_type_map_,
Artem Titov631cafa2018-08-21 21:01:00 +0200103 absl::make_unique<FakeNetworkPipe>(Clock::GetRealTimeClock(),
104 std::move(network)));
stefane74eef12016-01-08 06:47:13 -0800105 return send_transport_;
stefanf116bd02015-10-27 08:29:42 -0700106}
107
Stefan Holmerd20e6512016-01-12 15:51:22 +0100108size_t RampUpTester::GetNumVideoStreams() const {
109 return num_video_streams_;
110}
111
Stefan Holmerff2a6352016-01-14 10:00:21 +0100112size_t RampUpTester::GetNumAudioStreams() const {
113 return num_audio_streams_;
114}
115
philipel5ef2bc12017-02-21 07:28:31 -0800116size_t RampUpTester::GetNumFlexfecStreams() const {
117 return num_flexfec_streams_;
118}
119
perkjfa10b552016-10-02 23:45:26 -0700120class RampUpTester::VideoStreamFactory
121 : public VideoEncoderConfig::VideoStreamFactoryInterface {
122 public:
123 VideoStreamFactory() {}
124
125 private:
126 std::vector<VideoStream> CreateEncoderStreams(
127 int width,
128 int height,
129 const VideoEncoderConfig& encoder_config) override {
130 std::vector<VideoStream> streams =
131 test::CreateVideoStreams(width, height, encoder_config);
132 if (encoder_config.number_of_streams == 1) {
133 streams[0].target_bitrate_bps = streams[0].max_bitrate_bps = 2000000;
134 }
135 return streams;
136 }
137};
138
stefanff483612015-12-21 03:14:00 -0800139void RampUpTester::ModifyVideoConfigs(
stefan4fbd1452015-09-28 03:57:14 -0700140 VideoSendStream::Config* send_config,
141 std::vector<VideoReceiveStream::Config>* receive_configs,
142 VideoEncoderConfig* encoder_config) {
143 send_config->suspend_below_min_bitrate = true;
perkjfa10b552016-10-02 23:45:26 -0700144 encoder_config->number_of_streams = num_video_streams_;
145 encoder_config->max_bitrate_bps = 2000000;
146 encoder_config->video_stream_factory =
147 new rtc::RefCountedObject<RampUpTester::VideoStreamFactory>();
stefanff483612015-12-21 03:14:00 -0800148 if (num_video_streams_ == 1) {
stefan4fbd1452015-09-28 03:57:14 -0700149 // For single stream rampup until 1mbps
150 expected_bitrate_bps_ = kSingleStreamTargetBps;
151 } else {
152 // For multi stream rampup until all streams are being sent. That means
perkjfa10b552016-10-02 23:45:26 -0700153 // enough bitrate to send all the target streams plus the min bitrate of
stefan4fbd1452015-09-28 03:57:14 -0700154 // the last one.
perkjfa10b552016-10-02 23:45:26 -0700155 std::vector<VideoStream> streams = test::CreateVideoStreams(
156 test::CallTest::kDefaultWidth, test::CallTest::kDefaultHeight,
157 *encoder_config);
158 expected_bitrate_bps_ = streams.back().min_bitrate_bps;
159 for (size_t i = 0; i < streams.size() - 1; ++i) {
160 expected_bitrate_bps_ += streams[i].target_bitrate_bps;
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000161 }
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000162 }
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000163
stefan4fbd1452015-09-28 03:57:14 -0700164 send_config->rtp.extensions.clear();
165
166 bool remb;
stefan43edf0f2015-11-20 18:05:48 -0800167 bool transport_cc;
isheriff6f8d6862016-05-26 11:24:55 -0700168 if (extension_type_ == RtpExtension::kAbsSendTimeUri) {
stefan4fbd1452015-09-28 03:57:14 -0700169 remb = true;
stefan43edf0f2015-11-20 18:05:48 -0800170 transport_cc = false;
stefan4fbd1452015-09-28 03:57:14 -0700171 send_config->rtp.extensions.push_back(
172 RtpExtension(extension_type_.c_str(), kAbsSendTimeExtensionId));
isheriff6f8d6862016-05-26 11:24:55 -0700173 } else if (extension_type_ == RtpExtension::kTransportSequenceNumberUri) {
stefan4fbd1452015-09-28 03:57:14 -0700174 remb = false;
stefan43edf0f2015-11-20 18:05:48 -0800175 transport_cc = true;
stefan4fbd1452015-09-28 03:57:14 -0700176 send_config->rtp.extensions.push_back(RtpExtension(
177 extension_type_.c_str(), kTransportSequenceNumberExtensionId));
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000178 } else {
stefan4fbd1452015-09-28 03:57:14 -0700179 remb = true;
stefan43edf0f2015-11-20 18:05:48 -0800180 transport_cc = false;
stefan4fbd1452015-09-28 03:57:14 -0700181 send_config->rtp.extensions.push_back(RtpExtension(
182 extension_type_.c_str(), kTransmissionTimeOffsetExtensionId));
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000183 }
stefan4fbd1452015-09-28 03:57:14 -0700184
185 send_config->rtp.nack.rtp_history_ms = test::CallTest::kNackRtpHistoryMs;
stefanff483612015-12-21 03:14:00 -0800186 send_config->rtp.ssrcs = video_ssrcs_;
stefan4fbd1452015-09-28 03:57:14 -0700187 if (rtx_) {
188 send_config->rtp.rtx.payload_type = test::CallTest::kSendRtxPayloadType;
stefanff483612015-12-21 03:14:00 -0800189 send_config->rtp.rtx.ssrcs = video_rtx_ssrcs_;
stefan4fbd1452015-09-28 03:57:14 -0700190 }
191 if (red_) {
brandtrb5f2c3f2016-10-04 23:28:39 -0700192 send_config->rtp.ulpfec.ulpfec_payload_type =
stefan4fbd1452015-09-28 03:57:14 -0700193 test::CallTest::kUlpfecPayloadType;
brandtrb5f2c3f2016-10-04 23:28:39 -0700194 send_config->rtp.ulpfec.red_payload_type = test::CallTest::kRedPayloadType;
brandtrfbfb5362016-11-17 04:18:37 -0800195 if (rtx_) {
196 send_config->rtp.ulpfec.red_rtx_payload_type =
197 test::CallTest::kRtxRedPayloadType;
198 }
stefan4fbd1452015-09-28 03:57:14 -0700199 }
200
201 size_t i = 0;
202 for (VideoReceiveStream::Config& recv_config : *receive_configs) {
203 recv_config.rtp.remb = remb;
stefan43edf0f2015-11-20 18:05:48 -0800204 recv_config.rtp.transport_cc = transport_cc;
stefan4fbd1452015-09-28 03:57:14 -0700205 recv_config.rtp.extensions = send_config->rtp.extensions;
206
stefanff483612015-12-21 03:14:00 -0800207 recv_config.rtp.remote_ssrc = video_ssrcs_[i];
stefan4fbd1452015-09-28 03:57:14 -0700208 recv_config.rtp.nack.rtp_history_ms = send_config->rtp.nack.rtp_history_ms;
209
210 if (red_) {
nisse3b3622f2017-09-26 02:49:21 -0700211 recv_config.rtp.red_payload_type =
brandtrb5f2c3f2016-10-04 23:28:39 -0700212 send_config->rtp.ulpfec.red_payload_type;
nisse3b3622f2017-09-26 02:49:21 -0700213 recv_config.rtp.ulpfec_payload_type =
brandtrb5f2c3f2016-10-04 23:28:39 -0700214 send_config->rtp.ulpfec.ulpfec_payload_type;
brandtrfbfb5362016-11-17 04:18:37 -0800215 if (rtx_) {
nisseca5706d2017-09-11 02:32:16 -0700216 recv_config.rtp.rtx_associated_payload_types
217 [send_config->rtp.ulpfec.red_rtx_payload_type] =
218 send_config->rtp.ulpfec.red_payload_type;
brandtrfbfb5362016-11-17 04:18:37 -0800219 }
stefan4fbd1452015-09-28 03:57:14 -0700220 }
221
222 if (rtx_) {
brandtr14742122017-01-27 04:53:07 -0800223 recv_config.rtp.rtx_ssrc = video_rtx_ssrcs_[i];
224 recv_config.rtp
nisse26e3abb2017-08-25 04:44:25 -0700225 .rtx_associated_payload_types[send_config->rtp.rtx.payload_type] =
Niels Möller259a4972018-04-05 15:36:51 +0200226 send_config->rtp.payload_type;
stefan4fbd1452015-09-28 03:57:14 -0700227 }
228 ++i;
229 }
philipel5ef2bc12017-02-21 07:28:31 -0800230
231 RTC_DCHECK_LE(num_flexfec_streams_, 1);
232 if (num_flexfec_streams_ == 1) {
233 send_config->rtp.flexfec.payload_type = test::CallTest::kFlexfecPayloadType;
234 send_config->rtp.flexfec.ssrc = test::CallTest::kFlexfecSendSsrc;
235 send_config->rtp.flexfec.protected_media_ssrcs = {video_ssrcs_[0]};
236 }
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000237}
238
Stefan Holmerff2a6352016-01-14 10:00:21 +0100239void RampUpTester::ModifyAudioConfigs(
240 AudioSendStream::Config* send_config,
241 std::vector<AudioReceiveStream::Config>* receive_configs) {
242 if (num_audio_streams_ == 0)
243 return;
244
isheriff6f8d6862016-05-26 11:24:55 -0700245 EXPECT_NE(RtpExtension::kTimestampOffsetUri, extension_type_)
Stefan Holmerff2a6352016-01-14 10:00:21 +0100246 << "Audio BWE not supported with toffset.";
philipel5ef2bc12017-02-21 07:28:31 -0800247 EXPECT_NE(RtpExtension::kAbsSendTimeUri, extension_type_)
248 << "Audio BWE not supported with abs-send-time.";
Stefan Holmerff2a6352016-01-14 10:00:21 +0100249
250 send_config->rtp.ssrc = audio_ssrcs_[0];
251 send_config->rtp.extensions.clear();
252
minyue10cbb462016-11-07 09:29:22 -0800253 send_config->min_bitrate_bps = 6000;
254 send_config->max_bitrate_bps = 60000;
mflodman86cc6ff2016-07-26 04:44:06 -0700255
Stefan Holmerff2a6352016-01-14 10:00:21 +0100256 bool transport_cc = false;
philipel5ef2bc12017-02-21 07:28:31 -0800257 if (extension_type_ == RtpExtension::kTransportSequenceNumberUri) {
Stefan Holmerff2a6352016-01-14 10:00:21 +0100258 transport_cc = true;
259 send_config->rtp.extensions.push_back(RtpExtension(
260 extension_type_.c_str(), kTransportSequenceNumberExtensionId));
261 }
262
263 for (AudioReceiveStream::Config& recv_config : *receive_configs) {
Stefan Holmerff2a6352016-01-14 10:00:21 +0100264 recv_config.rtp.transport_cc = transport_cc;
265 recv_config.rtp.extensions = send_config->rtp.extensions;
266 recv_config.rtp.remote_ssrc = send_config->rtp.ssrc;
267 }
268}
269
philipel5ef2bc12017-02-21 07:28:31 -0800270void RampUpTester::ModifyFlexfecConfigs(
271 std::vector<FlexfecReceiveStream::Config>* receive_configs) {
272 if (num_flexfec_streams_ == 0)
273 return;
274 RTC_DCHECK_EQ(1, num_flexfec_streams_);
275 (*receive_configs)[0].payload_type = test::CallTest::kFlexfecPayloadType;
276 (*receive_configs)[0].remote_ssrc = test::CallTest::kFlexfecSendSsrc;
277 (*receive_configs)[0].protected_media_ssrcs = {video_ssrcs_[0]};
278 (*receive_configs)[0].local_ssrc = video_ssrcs_[0];
279 if (extension_type_ == RtpExtension::kAbsSendTimeUri) {
280 (*receive_configs)[0].transport_cc = false;
281 (*receive_configs)[0].rtp_header_extensions.push_back(
282 RtpExtension(extension_type_.c_str(), kAbsSendTimeExtensionId));
283 } else if (extension_type_ == RtpExtension::kTransportSequenceNumberUri) {
284 (*receive_configs)[0].transport_cc = true;
285 (*receive_configs)[0].rtp_header_extensions.push_back(RtpExtension(
286 extension_type_.c_str(), kTransportSequenceNumberExtensionId));
287 }
288}
289
stefan4fbd1452015-09-28 03:57:14 -0700290void RampUpTester::OnCallsCreated(Call* sender_call, Call* receiver_call) {
291 sender_call_ = sender_call;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000292}
293
tommi0f8b4032017-02-22 11:22:05 -0800294void RampUpTester::BitrateStatsPollingThread(void* obj) {
295 static_cast<RampUpTester*>(obj)->PollStats();
pbos@webrtc.org32452b22014-10-22 12:15:24 +0000296}
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000297
tommi0f8b4032017-02-22 11:22:05 -0800298void RampUpTester::PollStats() {
299 do {
300 if (sender_call_) {
301 Call::Stats stats = sender_call_->GetStats();
stefan4fbd1452015-09-28 03:57:14 -0700302
tommi0f8b4032017-02-22 11:22:05 -0800303 EXPECT_GE(stats.send_bandwidth_bps, start_bitrate_bps_);
304 EXPECT_GE(expected_bitrate_bps_, 0);
305 if (stats.send_bandwidth_bps >= expected_bitrate_bps_ &&
306 (min_run_time_ms_ == -1 ||
307 clock_->TimeInMilliseconds() - test_start_ms_ >= min_run_time_ms_)) {
308 ramp_up_finished_ms_ = clock_->TimeInMilliseconds();
309 observation_complete_.Set();
310 }
stefan4fbd1452015-09-28 03:57:14 -0700311 }
tommi0f8b4032017-02-22 11:22:05 -0800312 } while (!stop_event_.Wait(kPollIntervalMs));
Erik Språng468e62a2015-07-06 10:50:47 +0200313}
314
stefan4fbd1452015-09-28 03:57:14 -0700315void RampUpTester::ReportResult(const std::string& measurement,
316 size_t value,
317 const std::string& units) const {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000318 webrtc::test::PrintResult(
319 measurement, "",
stefanff483612015-12-21 03:14:00 -0800320 ::testing::UnitTest::GetInstance()->current_test_info()->name(), value,
321 units, false);
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000322}
323
stefan092508a2015-09-29 02:26:42 -0700324void RampUpTester::AccumulateStats(const VideoSendStream::StreamStats& stream,
325 size_t* total_packets_sent,
326 size_t* total_sent,
327 size_t* padding_sent,
328 size_t* media_sent) const {
stefan4fbd1452015-09-28 03:57:14 -0700329 *total_packets_sent += stream.rtp_stats.transmitted.packets +
330 stream.rtp_stats.retransmitted.packets +
331 stream.rtp_stats.fec.packets;
332 *total_sent += stream.rtp_stats.transmitted.TotalBytes() +
333 stream.rtp_stats.retransmitted.TotalBytes() +
334 stream.rtp_stats.fec.TotalBytes();
335 *padding_sent += stream.rtp_stats.transmitted.padding_bytes +
336 stream.rtp_stats.retransmitted.padding_bytes +
337 stream.rtp_stats.fec.padding_bytes;
338 *media_sent += stream.rtp_stats.MediaPayloadBytes();
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000339}
340
stefan4fbd1452015-09-28 03:57:14 -0700341void RampUpTester::TriggerTestDone() {
Erik Språngf3a7c9d2015-10-05 14:03:22 +0200342 RTC_DCHECK_GE(test_start_ms_, 0);
343
Stefan Holmerff2a6352016-01-14 10:00:21 +0100344 // TODO(holmer): Add audio send stats here too when those APIs are available.
mflodman86cc6ff2016-07-26 04:44:06 -0700345 if (!send_stream_)
346 return;
347
stefan4fbd1452015-09-28 03:57:14 -0700348 VideoSendStream::Stats send_stats = send_stream_->GetStats();
349
350 size_t total_packets_sent = 0;
351 size_t total_sent = 0;
352 size_t padding_sent = 0;
353 size_t media_sent = 0;
stefanff483612015-12-21 03:14:00 -0800354 for (uint32_t ssrc : video_ssrcs_) {
stefan092508a2015-09-29 02:26:42 -0700355 AccumulateStats(send_stats.substreams[ssrc], &total_packets_sent,
356 &total_sent, &padding_sent, &media_sent);
stefan4fbd1452015-09-28 03:57:14 -0700357 }
358
359 size_t rtx_total_packets_sent = 0;
360 size_t rtx_total_sent = 0;
361 size_t rtx_padding_sent = 0;
362 size_t rtx_media_sent = 0;
stefanff483612015-12-21 03:14:00 -0800363 for (uint32_t rtx_ssrc : video_rtx_ssrcs_) {
stefan092508a2015-09-29 02:26:42 -0700364 AccumulateStats(send_stats.substreams[rtx_ssrc], &rtx_total_packets_sent,
365 &rtx_total_sent, &rtx_padding_sent, &rtx_media_sent);
stefan4fbd1452015-09-28 03:57:14 -0700366 }
367
stefan5a2c5062017-01-27 06:43:18 -0800368 if (report_perf_stats_) {
stefan5a2c5062017-01-27 06:43:18 -0800369 ReportResult("ramp-up-media-sent", media_sent, "bytes");
370 ReportResult("ramp-up-padding-sent", padding_sent, "bytes");
stefan5a2c5062017-01-27 06:43:18 -0800371 ReportResult("ramp-up-rtx-media-sent", rtx_media_sent, "bytes");
372 ReportResult("ramp-up-rtx-padding-sent", rtx_padding_sent, "bytes");
373 if (ramp_up_finished_ms_ >= 0) {
374 ReportResult("ramp-up-time", ramp_up_finished_ms_ - test_start_ms_,
375 "milliseconds");
376 }
377 ReportResult("ramp-up-average-network-latency",
378 send_transport_->GetAverageDelayMs(), "milliseconds");
stefan4fbd1452015-09-28 03:57:14 -0700379 }
380}
381
382void RampUpTester::PerformTest() {
Erik Språngf3a7c9d2015-10-05 14:03:22 +0200383 test_start_ms_ = clock_->TimeInMilliseconds();
Peter Boström8c38e8b2015-11-26 17:45:47 +0100384 poller_thread_.Start();
Peter Boström5811a392015-12-10 13:02:50 +0100385 EXPECT_TRUE(Wait()) << "Timed out while waiting for ramp-up to complete.";
stefan4fbd1452015-09-28 03:57:14 -0700386 TriggerTestDone();
tommi0f8b4032017-02-22 11:22:05 -0800387 stop_event_.Set();
Peter Boström8c38e8b2015-11-26 17:45:47 +0100388 poller_thread_.Stop();
stefan4fbd1452015-09-28 03:57:14 -0700389}
390
Stefan Holmerff2a6352016-01-14 10:00:21 +0100391RampUpDownUpTester::RampUpDownUpTester(size_t num_video_streams,
392 size_t num_audio_streams,
philipel5ef2bc12017-02-21 07:28:31 -0800393 size_t num_flexfec_streams,
stefan4fbd1452015-09-28 03:57:14 -0700394 unsigned int start_bitrate_bps,
395 const std::string& extension_type,
396 bool rtx,
philipel5ef2bc12017-02-21 07:28:31 -0800397 bool red,
stefan45b5fe52017-03-09 06:27:02 -0800398 const std::vector<int>& loss_rates,
399 bool report_perf_stats)
Stefan Holmerff2a6352016-01-14 10:00:21 +0100400 : RampUpTester(num_video_streams,
401 num_audio_streams,
philipel5ef2bc12017-02-21 07:28:31 -0800402 num_flexfec_streams,
Stefan Holmerff2a6352016-01-14 10:00:21 +0100403 start_bitrate_bps,
stefan5a2c5062017-01-27 06:43:18 -0800404 0,
Stefan Holmerff2a6352016-01-14 10:00:21 +0100405 extension_type,
406 rtx,
stefan5a2c5062017-01-27 06:43:18 -0800407 red,
stefan45b5fe52017-03-09 06:27:02 -0800408 report_perf_stats),
stefan76d9c9c2017-04-01 06:51:09 -0700409 link_rates_({4 * GetExpectedHighBitrate() / (3 * 1000),
410 kLowBandwidthLimitBps / 1000,
411 4 * GetExpectedHighBitrate() / (3 * 1000), 0}),
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000412 test_state_(kFirstRampup),
philipel5ef2bc12017-02-21 07:28:31 -0800413 next_state_(kTransitionToNextState),
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000414 state_start_ms_(clock_->TimeInMilliseconds()),
stefan4fbd1452015-09-28 03:57:14 -0700415 interval_start_ms_(clock_->TimeInMilliseconds()),
philipel5ef2bc12017-02-21 07:28:31 -0800416 sent_bytes_(0),
417 loss_rates_(loss_rates) {
418 forward_transport_config_.link_capacity_kbps = link_rates_[test_state_];
419 forward_transport_config_.queue_delay_ms = 100;
420 forward_transport_config_.loss_percent = loss_rates_[test_state_];
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000421}
422
stefan4fbd1452015-09-28 03:57:14 -0700423RampUpDownUpTester::~RampUpDownUpTester() {}
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000424
tommi0f8b4032017-02-22 11:22:05 -0800425void RampUpDownUpTester::PollStats() {
426 do {
Alex Narest78609d52017-10-20 10:37:47 +0200427 int transmit_bitrate_bps = 0;
428 bool suspended = false;
429 if (num_video_streams_ > 0) {
tommi0f8b4032017-02-22 11:22:05 -0800430 webrtc::VideoSendStream::Stats stats = send_stream_->GetStats();
tommi0f8b4032017-02-22 11:22:05 -0800431 for (auto it : stats.substreams) {
432 transmit_bitrate_bps += it.second.total_bitrate_bps;
433 }
Alex Narest78609d52017-10-20 10:37:47 +0200434 suspended = stats.suspended;
435 }
436 if (num_audio_streams_ > 0 && sender_call_ != nullptr) {
tommi0f8b4032017-02-22 11:22:05 -0800437 // An audio send stream doesn't have bitrate stats, so the call send BW is
438 // currently used instead.
Alex Narest78609d52017-10-20 10:37:47 +0200439 transmit_bitrate_bps = sender_call_->GetStats().send_bandwidth_bps;
mflodman@webrtc.orgeb16b812014-06-16 08:57:39 +0000440 }
Alex Narest78609d52017-10-20 10:37:47 +0200441 EvolveTestState(transmit_bitrate_bps, suspended);
tommi0f8b4032017-02-22 11:22:05 -0800442 } while (!stop_event_.Wait(kPollIntervalMs));
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000443}
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000444
Sebastian Jansson72582242018-07-13 13:19:42 +0200445void RampUpDownUpTester::ModifyReceiverCallConfig(Call::Config* config) {
446 config->bitrate_config.min_bitrate_bps = 10000;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000447}
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000448
stefan4fbd1452015-09-28 03:57:14 -0700449std::string RampUpDownUpTester::GetModifierString() const {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000450 std::string str("_");
stefanff483612015-12-21 03:14:00 -0800451 if (num_video_streams_ > 0) {
Jonas Olsson0a713b62018-04-04 15:49:32 +0200452 str += rtc::ToString(num_video_streams_);
stefanff483612015-12-21 03:14:00 -0800453 str += "stream";
454 str += (num_video_streams_ > 1 ? "s" : "");
455 str += "_";
456 }
457 if (num_audio_streams_ > 0) {
Jonas Olsson0a713b62018-04-04 15:49:32 +0200458 str += rtc::ToString(num_audio_streams_);
stefanff483612015-12-21 03:14:00 -0800459 str += "stream";
460 str += (num_audio_streams_ > 1 ? "s" : "");
461 str += "_";
462 }
stefan4fbd1452015-09-28 03:57:14 -0700463 str += (rtx_ ? "" : "no");
Edward Lemurdd3987f2018-01-04 19:44:54 +0100464 str += "rtx_";
465 str += (red_ ? "" : "no");
466 str += "red";
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000467 return str;
468}
andresp@webrtc.orgc1480792014-03-20 03:23:55 +0000469
stefandb752f92016-12-05 08:23:40 -0800470int RampUpDownUpTester::GetExpectedHighBitrate() const {
stefan38d8b3c2017-01-09 04:19:24 -0800471 int expected_bitrate_bps = 0;
472 if (num_audio_streams_ > 0)
473 expected_bitrate_bps += kExpectedHighAudioBitrateBps;
474 if (num_video_streams_ > 0)
475 expected_bitrate_bps += kExpectedHighVideoBitrateBps;
476 return expected_bitrate_bps;
477}
478
philipel5ef2bc12017-02-21 07:28:31 -0800479size_t RampUpDownUpTester::GetFecBytes() const {
480 size_t flex_fec_bytes = 0;
481 if (num_flexfec_streams_ > 0) {
482 webrtc::VideoSendStream::Stats stats = send_stream_->GetStats();
483 for (const auto& kv : stats.substreams)
484 flex_fec_bytes += kv.second.rtp_stats.fec.TotalBytes();
485 }
486 return flex_fec_bytes;
487}
488
489bool RampUpDownUpTester::ExpectingFec() const {
490 return num_flexfec_streams_ > 0 && forward_transport_config_.loss_percent > 0;
491}
492
stefan4fbd1452015-09-28 03:57:14 -0700493void RampUpDownUpTester::EvolveTestState(int bitrate_bps, bool suspended) {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000494 int64_t now = clock_->TimeInMilliseconds();
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000495 switch (test_state_) {
philipel5ef2bc12017-02-21 07:28:31 -0800496 case kFirstRampup:
stefan4fbd1452015-09-28 03:57:14 -0700497 EXPECT_FALSE(suspended);
stefandb752f92016-12-05 08:23:40 -0800498 if (bitrate_bps >= GetExpectedHighBitrate()) {
stefan45b5fe52017-03-09 06:27:02 -0800499 if (report_perf_stats_) {
500 webrtc::test::PrintResult("ramp_up_down_up", GetModifierString(),
501 "first_rampup", now - state_start_ms_, "ms",
502 false);
503 }
philipel5ef2bc12017-02-21 07:28:31 -0800504 // Apply loss during the transition between states if FEC is enabled.
505 forward_transport_config_.loss_percent = loss_rates_[test_state_];
506 test_state_ = kTransitionToNextState;
507 next_state_ = kLowRate;
andresp@webrtc.orgc1480792014-03-20 03:23:55 +0000508 }
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000509 break;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000510 case kLowRate: {
mflodman86cc6ff2016-07-26 04:44:06 -0700511 // Audio streams are never suspended.
512 bool check_suspend_state = num_video_streams_ > 0;
Sebastian Jansson12fb1702018-02-23 11:34:18 +0100513 if (bitrate_bps < kLowBandwidthLimitBps + kLowBitrateMarginBps &&
mflodman86cc6ff2016-07-26 04:44:06 -0700514 suspended == check_suspend_state) {
stefan45b5fe52017-03-09 06:27:02 -0800515 if (report_perf_stats_) {
516 webrtc::test::PrintResult("ramp_up_down_up", GetModifierString(),
517 "rampdown", now - state_start_ms_, "ms",
518 false);
519 }
philipel5ef2bc12017-02-21 07:28:31 -0800520 // Apply loss during the transition between states if FEC is enabled.
521 forward_transport_config_.loss_percent = loss_rates_[test_state_];
522 test_state_ = kTransitionToNextState;
523 next_state_ = kSecondRampup;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000524 }
525 break;
526 }
philipel5ef2bc12017-02-21 07:28:31 -0800527 case kSecondRampup:
stefandb752f92016-12-05 08:23:40 -0800528 if (bitrate_bps >= GetExpectedHighBitrate() && !suspended) {
stefan45b5fe52017-03-09 06:27:02 -0800529 if (report_perf_stats_) {
530 webrtc::test::PrintResult("ramp_up_down_up", GetModifierString(),
531 "second_rampup", now - state_start_ms_,
532 "ms", false);
533 ReportResult("ramp-up-down-up-average-network-latency",
534 send_transport_->GetAverageDelayMs(), "milliseconds");
535 }
philipel5ef2bc12017-02-21 07:28:31 -0800536 // Apply loss during the transition between states if FEC is enabled.
537 forward_transport_config_.loss_percent = loss_rates_[test_state_];
538 test_state_ = kTransitionToNextState;
539 next_state_ = kTestEnd;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000540 }
541 break;
philipel5ef2bc12017-02-21 07:28:31 -0800542 case kTestEnd:
543 observation_complete_.Set();
544 break;
545 case kTransitionToNextState:
546 if (!ExpectingFec() || GetFecBytes() > 0) {
547 test_state_ = next_state_;
548 forward_transport_config_.link_capacity_kbps = link_rates_[test_state_];
549 // No loss while ramping up and down as it may affect the BWE
550 // negatively, making the test flaky.
551 forward_transport_config_.loss_percent = 0;
552 state_start_ms_ = now;
553 interval_start_ms_ = now;
554 sent_bytes_ = 0;
Artem Titov631cafa2018-08-21 21:01:00 +0200555 send_simulated_network_->SetConfig(forward_transport_config_);
philipel5ef2bc12017-02-21 07:28:31 -0800556 }
557 break;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000558 }
559}
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +0000560
stefan4fbd1452015-09-28 03:57:14 -0700561class RampUpTest : public test::CallTest {
Erik Språng6b8d3552015-09-24 15:06:57 +0200562 public:
stefan4fbd1452015-09-28 03:57:14 -0700563 RampUpTest() {}
Erik Språng6b8d3552015-09-24 15:06:57 +0200564};
565
Stefan Holmerff2a6352016-01-14 10:00:21 +0100566static const uint32_t kStartBitrateBps = 60000;
567
stefan38d8b3c2017-01-09 04:19:24 -0800568TEST_F(RampUpTest, UpDownUpAbsSendTimeSimulcastRedRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800569 std::vector<int> loss_rates = {0, 0, 0, 0};
570 RampUpDownUpTester test(3, 0, 0, kStartBitrateBps,
stefan45b5fe52017-03-09 06:27:02 -0800571 RtpExtension::kAbsSendTimeUri, true, true, loss_rates,
572 true);
stefane74eef12016-01-08 06:47:13 -0800573 RunBaseTest(&test);
Shao Changbine62202f2015-04-21 20:24:50 +0800574}
Stefan Holmerff2a6352016-01-14 10:00:21 +0100575
Taylor Brandstetterba6b5032018-02-16 09:59:56 -0800576// TODO(bugs.webrtc.org/8878)
577#if defined(WEBRTC_MAC)
578#define MAYBE_UpDownUpTransportSequenceNumberRtx \
579 DISABLED_UpDownUpTransportSequenceNumberRtx
580#else
581#define MAYBE_UpDownUpTransportSequenceNumberRtx \
582 UpDownUpTransportSequenceNumberRtx
583#endif
584TEST_F(RampUpTest, MAYBE_UpDownUpTransportSequenceNumberRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800585 std::vector<int> loss_rates = {0, 0, 0, 0};
586 RampUpDownUpTester test(3, 0, 0, kStartBitrateBps,
isheriff6f8d6862016-05-26 11:24:55 -0700587 RtpExtension::kTransportSequenceNumberUri, true,
stefan45b5fe52017-03-09 06:27:02 -0800588 false, loss_rates, true);
philipel5ef2bc12017-02-21 07:28:31 -0800589 RunBaseTest(&test);
590}
591
stefan45b5fe52017-03-09 06:27:02 -0800592// TODO(holmer): Tests which don't report perf stats should be moved to a
593// different executable since they per definition are not perf tests.
Taylor Brandstetter05d98222017-10-10 12:12:53 -0700594// This test is disabled because it crashes on Linux, and is flaky on other
595// platforms. See: crbug.com/webrtc/7919
596TEST_F(RampUpTest, DISABLED_UpDownUpTransportSequenceNumberPacketLoss) {
philipel5ef2bc12017-02-21 07:28:31 -0800597 std::vector<int> loss_rates = {20, 0, 0, 0};
598 RampUpDownUpTester test(1, 0, 1, kStartBitrateBps,
599 RtpExtension::kTransportSequenceNumberUri, true,
stefan45b5fe52017-03-09 06:27:02 -0800600 false, loss_rates, false);
Stefan Holmerff2a6352016-01-14 10:00:21 +0100601 RunBaseTest(&test);
602}
603
Taylor Brandstetterab86e7f2018-02-12 15:16:02 -0800604// TODO(bugs.webrtc.org/8878)
605#if defined(WEBRTC_MAC)
606#define MAYBE_UpDownUpAudioVideoTransportSequenceNumberRtx \
607 DISABLED_UpDownUpAudioVideoTransportSequenceNumberRtx
608#else
609#define MAYBE_UpDownUpAudioVideoTransportSequenceNumberRtx \
610 UpDownUpAudioVideoTransportSequenceNumberRtx
611#endif
612TEST_F(RampUpTest, MAYBE_UpDownUpAudioVideoTransportSequenceNumberRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800613 std::vector<int> loss_rates = {0, 0, 0, 0};
614 RampUpDownUpTester test(3, 1, 0, kStartBitrateBps,
isheriff6f8d6862016-05-26 11:24:55 -0700615 RtpExtension::kTransportSequenceNumberUri, true,
stefanff2ebf52017-03-13 01:27:03 -0700616 false, loss_rates, false);
Stefan Holmerff2a6352016-01-14 10:00:21 +0100617 RunBaseTest(&test);
618}
619
stefan38d8b3c2017-01-09 04:19:24 -0800620TEST_F(RampUpTest, UpDownUpAudioTransportSequenceNumberRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800621 std::vector<int> loss_rates = {0, 0, 0, 0};
622 RampUpDownUpTester test(0, 1, 0, kStartBitrateBps,
mflodman86cc6ff2016-07-26 04:44:06 -0700623 RtpExtension::kTransportSequenceNumberUri, true,
stefanff2ebf52017-03-13 01:27:03 -0700624 false, loss_rates, false);
mflodman86cc6ff2016-07-26 04:44:06 -0700625 RunBaseTest(&test);
626}
627
stefan38d8b3c2017-01-09 04:19:24 -0800628TEST_F(RampUpTest, TOffsetSimulcastRedRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800629 RampUpTester test(3, 0, 0, 0, 0, RtpExtension::kTimestampOffsetUri, true,
630 true, true);
stefan38d8b3c2017-01-09 04:19:24 -0800631 RunBaseTest(&test);
632}
633
634TEST_F(RampUpTest, AbsSendTime) {
philipel5ef2bc12017-02-21 07:28:31 -0800635 RampUpTester test(1, 0, 0, 0, 0, RtpExtension::kAbsSendTimeUri, false, false,
stefanff2ebf52017-03-13 01:27:03 -0700636 false);
stefane74eef12016-01-08 06:47:13 -0800637 RunBaseTest(&test);
pbos@webrtc.org85bd53e2014-12-10 10:36:20 +0000638}
639
stefan38d8b3c2017-01-09 04:19:24 -0800640TEST_F(RampUpTest, AbsSendTimeSimulcastRedRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800641 RampUpTester test(3, 0, 0, 0, 0, RtpExtension::kAbsSendTimeUri, true, true,
stefan5a2c5062017-01-27 06:43:18 -0800642 true);
stefane74eef12016-01-08 06:47:13 -0800643 RunBaseTest(&test);
pbos@webrtc.org85bd53e2014-12-10 10:36:20 +0000644}
645
stefan38d8b3c2017-01-09 04:19:24 -0800646TEST_F(RampUpTest, TransportSequenceNumber) {
philipel5ef2bc12017-02-21 07:28:31 -0800647 RampUpTester test(1, 0, 0, 0, 0, RtpExtension::kTransportSequenceNumberUri,
stefanff2ebf52017-03-13 01:27:03 -0700648 false, false, false);
stefane74eef12016-01-08 06:47:13 -0800649 RunBaseTest(&test);
Erik Språng6b8d3552015-09-24 15:06:57 +0200650}
651
652TEST_F(RampUpTest, TransportSequenceNumberSimulcast) {
philipel5ef2bc12017-02-21 07:28:31 -0800653 RampUpTester test(3, 0, 0, 0, 0, RtpExtension::kTransportSequenceNumberUri,
stefanff2ebf52017-03-13 01:27:03 -0700654 false, false, false);
stefane74eef12016-01-08 06:47:13 -0800655 RunBaseTest(&test);
Erik Språng6b8d3552015-09-24 15:06:57 +0200656}
657
stefan38d8b3c2017-01-09 04:19:24 -0800658TEST_F(RampUpTest, TransportSequenceNumberSimulcastRedRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800659 RampUpTester test(3, 0, 0, 0, 0, RtpExtension::kTransportSequenceNumberUri,
stefan5a2c5062017-01-27 06:43:18 -0800660 true, true, true);
661 RunBaseTest(&test);
662}
663
Taylor Brandstetterab86e7f2018-02-12 15:16:02 -0800664// TODO(bugs.webrtc.org/8878)
665#if defined(WEBRTC_MAC)
666#define MAYBE_AudioTransportSequenceNumber DISABLED_AudioTransportSequenceNumber
667#else
668#define MAYBE_AudioTransportSequenceNumber AudioTransportSequenceNumber
669#endif
670TEST_F(RampUpTest, MAYBE_AudioTransportSequenceNumber) {
philipel5ef2bc12017-02-21 07:28:31 -0800671 RampUpTester test(0, 1, 0, 300000, 10000,
stefan5a2c5062017-01-27 06:43:18 -0800672 RtpExtension::kTransportSequenceNumberUri, false, false,
673 false);
stefane74eef12016-01-08 06:47:13 -0800674 RunBaseTest(&test);
Erik Språng6b8d3552015-09-24 15:06:57 +0200675}
pbos@webrtc.org744fbc72013-09-10 09:26:25 +0000676} // namespace webrtc