blob: 8eb451ac04f73a7b85aebc82effe40b7b156999b [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 {
Ilya Nikolaevskiyb0588e62018-08-27 14:12:27 +0200152 // To ensure simulcast rate allocation.
153 send_config->rtp.payload_name = "VP8";
154 encoder_config->codec_type = kVideoCodecVP8;
perkjfa10b552016-10-02 23:45:26 -0700155 std::vector<VideoStream> streams = test::CreateVideoStreams(
156 test::CallTest::kDefaultWidth, test::CallTest::kDefaultHeight,
157 *encoder_config);
Ilya Nikolaevskiyb0588e62018-08-27 14:12:27 +0200158 // For multi stream rampup until all streams are being sent. That means
159 // enough bitrate to send all the target streams plus the min bitrate of
160 // the last one.
perkjfa10b552016-10-02 23:45:26 -0700161 expected_bitrate_bps_ = streams.back().min_bitrate_bps;
162 for (size_t i = 0; i < streams.size() - 1; ++i) {
163 expected_bitrate_bps_ += streams[i].target_bitrate_bps;
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000164 }
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000165 }
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000166
stefan4fbd1452015-09-28 03:57:14 -0700167 send_config->rtp.extensions.clear();
168
169 bool remb;
stefan43edf0f2015-11-20 18:05:48 -0800170 bool transport_cc;
isheriff6f8d6862016-05-26 11:24:55 -0700171 if (extension_type_ == RtpExtension::kAbsSendTimeUri) {
stefan4fbd1452015-09-28 03:57:14 -0700172 remb = true;
stefan43edf0f2015-11-20 18:05:48 -0800173 transport_cc = false;
stefan4fbd1452015-09-28 03:57:14 -0700174 send_config->rtp.extensions.push_back(
175 RtpExtension(extension_type_.c_str(), kAbsSendTimeExtensionId));
isheriff6f8d6862016-05-26 11:24:55 -0700176 } else if (extension_type_ == RtpExtension::kTransportSequenceNumberUri) {
stefan4fbd1452015-09-28 03:57:14 -0700177 remb = false;
stefan43edf0f2015-11-20 18:05:48 -0800178 transport_cc = true;
stefan4fbd1452015-09-28 03:57:14 -0700179 send_config->rtp.extensions.push_back(RtpExtension(
180 extension_type_.c_str(), kTransportSequenceNumberExtensionId));
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000181 } else {
stefan4fbd1452015-09-28 03:57:14 -0700182 remb = true;
stefan43edf0f2015-11-20 18:05:48 -0800183 transport_cc = false;
stefan4fbd1452015-09-28 03:57:14 -0700184 send_config->rtp.extensions.push_back(RtpExtension(
185 extension_type_.c_str(), kTransmissionTimeOffsetExtensionId));
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000186 }
stefan4fbd1452015-09-28 03:57:14 -0700187
188 send_config->rtp.nack.rtp_history_ms = test::CallTest::kNackRtpHistoryMs;
stefanff483612015-12-21 03:14:00 -0800189 send_config->rtp.ssrcs = video_ssrcs_;
stefan4fbd1452015-09-28 03:57:14 -0700190 if (rtx_) {
191 send_config->rtp.rtx.payload_type = test::CallTest::kSendRtxPayloadType;
stefanff483612015-12-21 03:14:00 -0800192 send_config->rtp.rtx.ssrcs = video_rtx_ssrcs_;
stefan4fbd1452015-09-28 03:57:14 -0700193 }
194 if (red_) {
brandtrb5f2c3f2016-10-04 23:28:39 -0700195 send_config->rtp.ulpfec.ulpfec_payload_type =
stefan4fbd1452015-09-28 03:57:14 -0700196 test::CallTest::kUlpfecPayloadType;
brandtrb5f2c3f2016-10-04 23:28:39 -0700197 send_config->rtp.ulpfec.red_payload_type = test::CallTest::kRedPayloadType;
brandtrfbfb5362016-11-17 04:18:37 -0800198 if (rtx_) {
199 send_config->rtp.ulpfec.red_rtx_payload_type =
200 test::CallTest::kRtxRedPayloadType;
201 }
stefan4fbd1452015-09-28 03:57:14 -0700202 }
203
204 size_t i = 0;
205 for (VideoReceiveStream::Config& recv_config : *receive_configs) {
206 recv_config.rtp.remb = remb;
stefan43edf0f2015-11-20 18:05:48 -0800207 recv_config.rtp.transport_cc = transport_cc;
stefan4fbd1452015-09-28 03:57:14 -0700208 recv_config.rtp.extensions = send_config->rtp.extensions;
Ilya Nikolaevskiyb0588e62018-08-27 14:12:27 +0200209 recv_config.decoders.reserve(1);
210 recv_config.decoders[0].payload_type = send_config->rtp.payload_type;
Niels Möllercb7e1d22018-09-11 15:56:04 +0200211 recv_config.decoders[0].video_format =
212 SdpVideoFormat(send_config->rtp.payload_name);
stefan4fbd1452015-09-28 03:57:14 -0700213
stefanff483612015-12-21 03:14:00 -0800214 recv_config.rtp.remote_ssrc = video_ssrcs_[i];
stefan4fbd1452015-09-28 03:57:14 -0700215 recv_config.rtp.nack.rtp_history_ms = send_config->rtp.nack.rtp_history_ms;
216
217 if (red_) {
nisse3b3622f2017-09-26 02:49:21 -0700218 recv_config.rtp.red_payload_type =
brandtrb5f2c3f2016-10-04 23:28:39 -0700219 send_config->rtp.ulpfec.red_payload_type;
nisse3b3622f2017-09-26 02:49:21 -0700220 recv_config.rtp.ulpfec_payload_type =
brandtrb5f2c3f2016-10-04 23:28:39 -0700221 send_config->rtp.ulpfec.ulpfec_payload_type;
brandtrfbfb5362016-11-17 04:18:37 -0800222 if (rtx_) {
nisseca5706d2017-09-11 02:32:16 -0700223 recv_config.rtp.rtx_associated_payload_types
224 [send_config->rtp.ulpfec.red_rtx_payload_type] =
225 send_config->rtp.ulpfec.red_payload_type;
brandtrfbfb5362016-11-17 04:18:37 -0800226 }
stefan4fbd1452015-09-28 03:57:14 -0700227 }
228
229 if (rtx_) {
brandtr14742122017-01-27 04:53:07 -0800230 recv_config.rtp.rtx_ssrc = video_rtx_ssrcs_[i];
231 recv_config.rtp
nisse26e3abb2017-08-25 04:44:25 -0700232 .rtx_associated_payload_types[send_config->rtp.rtx.payload_type] =
Niels Möller259a4972018-04-05 15:36:51 +0200233 send_config->rtp.payload_type;
stefan4fbd1452015-09-28 03:57:14 -0700234 }
235 ++i;
236 }
philipel5ef2bc12017-02-21 07:28:31 -0800237
238 RTC_DCHECK_LE(num_flexfec_streams_, 1);
239 if (num_flexfec_streams_ == 1) {
240 send_config->rtp.flexfec.payload_type = test::CallTest::kFlexfecPayloadType;
241 send_config->rtp.flexfec.ssrc = test::CallTest::kFlexfecSendSsrc;
242 send_config->rtp.flexfec.protected_media_ssrcs = {video_ssrcs_[0]};
243 }
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000244}
245
Stefan Holmerff2a6352016-01-14 10:00:21 +0100246void RampUpTester::ModifyAudioConfigs(
247 AudioSendStream::Config* send_config,
248 std::vector<AudioReceiveStream::Config>* receive_configs) {
249 if (num_audio_streams_ == 0)
250 return;
251
isheriff6f8d6862016-05-26 11:24:55 -0700252 EXPECT_NE(RtpExtension::kTimestampOffsetUri, extension_type_)
Stefan Holmerff2a6352016-01-14 10:00:21 +0100253 << "Audio BWE not supported with toffset.";
philipel5ef2bc12017-02-21 07:28:31 -0800254 EXPECT_NE(RtpExtension::kAbsSendTimeUri, extension_type_)
255 << "Audio BWE not supported with abs-send-time.";
Stefan Holmerff2a6352016-01-14 10:00:21 +0100256
257 send_config->rtp.ssrc = audio_ssrcs_[0];
258 send_config->rtp.extensions.clear();
259
minyue10cbb462016-11-07 09:29:22 -0800260 send_config->min_bitrate_bps = 6000;
261 send_config->max_bitrate_bps = 60000;
mflodman86cc6ff2016-07-26 04:44:06 -0700262
Stefan Holmerff2a6352016-01-14 10:00:21 +0100263 bool transport_cc = false;
philipel5ef2bc12017-02-21 07:28:31 -0800264 if (extension_type_ == RtpExtension::kTransportSequenceNumberUri) {
Stefan Holmerff2a6352016-01-14 10:00:21 +0100265 transport_cc = true;
266 send_config->rtp.extensions.push_back(RtpExtension(
267 extension_type_.c_str(), kTransportSequenceNumberExtensionId));
268 }
269
270 for (AudioReceiveStream::Config& recv_config : *receive_configs) {
Stefan Holmerff2a6352016-01-14 10:00:21 +0100271 recv_config.rtp.transport_cc = transport_cc;
272 recv_config.rtp.extensions = send_config->rtp.extensions;
273 recv_config.rtp.remote_ssrc = send_config->rtp.ssrc;
274 }
275}
276
philipel5ef2bc12017-02-21 07:28:31 -0800277void RampUpTester::ModifyFlexfecConfigs(
278 std::vector<FlexfecReceiveStream::Config>* receive_configs) {
279 if (num_flexfec_streams_ == 0)
280 return;
281 RTC_DCHECK_EQ(1, num_flexfec_streams_);
282 (*receive_configs)[0].payload_type = test::CallTest::kFlexfecPayloadType;
283 (*receive_configs)[0].remote_ssrc = test::CallTest::kFlexfecSendSsrc;
284 (*receive_configs)[0].protected_media_ssrcs = {video_ssrcs_[0]};
285 (*receive_configs)[0].local_ssrc = video_ssrcs_[0];
286 if (extension_type_ == RtpExtension::kAbsSendTimeUri) {
287 (*receive_configs)[0].transport_cc = false;
288 (*receive_configs)[0].rtp_header_extensions.push_back(
289 RtpExtension(extension_type_.c_str(), kAbsSendTimeExtensionId));
290 } else if (extension_type_ == RtpExtension::kTransportSequenceNumberUri) {
291 (*receive_configs)[0].transport_cc = true;
292 (*receive_configs)[0].rtp_header_extensions.push_back(RtpExtension(
293 extension_type_.c_str(), kTransportSequenceNumberExtensionId));
294 }
295}
296
stefan4fbd1452015-09-28 03:57:14 -0700297void RampUpTester::OnCallsCreated(Call* sender_call, Call* receiver_call) {
298 sender_call_ = sender_call;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000299}
300
tommi0f8b4032017-02-22 11:22:05 -0800301void RampUpTester::BitrateStatsPollingThread(void* obj) {
302 static_cast<RampUpTester*>(obj)->PollStats();
pbos@webrtc.org32452b22014-10-22 12:15:24 +0000303}
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000304
tommi0f8b4032017-02-22 11:22:05 -0800305void RampUpTester::PollStats() {
306 do {
307 if (sender_call_) {
308 Call::Stats stats = sender_call_->GetStats();
stefan4fbd1452015-09-28 03:57:14 -0700309
tommi0f8b4032017-02-22 11:22:05 -0800310 EXPECT_GE(expected_bitrate_bps_, 0);
311 if (stats.send_bandwidth_bps >= expected_bitrate_bps_ &&
312 (min_run_time_ms_ == -1 ||
313 clock_->TimeInMilliseconds() - test_start_ms_ >= min_run_time_ms_)) {
314 ramp_up_finished_ms_ = clock_->TimeInMilliseconds();
315 observation_complete_.Set();
316 }
stefan4fbd1452015-09-28 03:57:14 -0700317 }
tommi0f8b4032017-02-22 11:22:05 -0800318 } while (!stop_event_.Wait(kPollIntervalMs));
Erik Språng468e62a2015-07-06 10:50:47 +0200319}
320
stefan4fbd1452015-09-28 03:57:14 -0700321void RampUpTester::ReportResult(const std::string& measurement,
322 size_t value,
323 const std::string& units) const {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000324 webrtc::test::PrintResult(
325 measurement, "",
stefanff483612015-12-21 03:14:00 -0800326 ::testing::UnitTest::GetInstance()->current_test_info()->name(), value,
327 units, false);
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000328}
329
stefan092508a2015-09-29 02:26:42 -0700330void RampUpTester::AccumulateStats(const VideoSendStream::StreamStats& stream,
331 size_t* total_packets_sent,
332 size_t* total_sent,
333 size_t* padding_sent,
334 size_t* media_sent) const {
stefan4fbd1452015-09-28 03:57:14 -0700335 *total_packets_sent += stream.rtp_stats.transmitted.packets +
336 stream.rtp_stats.retransmitted.packets +
337 stream.rtp_stats.fec.packets;
338 *total_sent += stream.rtp_stats.transmitted.TotalBytes() +
339 stream.rtp_stats.retransmitted.TotalBytes() +
340 stream.rtp_stats.fec.TotalBytes();
341 *padding_sent += stream.rtp_stats.transmitted.padding_bytes +
342 stream.rtp_stats.retransmitted.padding_bytes +
343 stream.rtp_stats.fec.padding_bytes;
344 *media_sent += stream.rtp_stats.MediaPayloadBytes();
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000345}
346
stefan4fbd1452015-09-28 03:57:14 -0700347void RampUpTester::TriggerTestDone() {
Erik Språngf3a7c9d2015-10-05 14:03:22 +0200348 RTC_DCHECK_GE(test_start_ms_, 0);
349
Stefan Holmerff2a6352016-01-14 10:00:21 +0100350 // TODO(holmer): Add audio send stats here too when those APIs are available.
mflodman86cc6ff2016-07-26 04:44:06 -0700351 if (!send_stream_)
352 return;
353
stefan4fbd1452015-09-28 03:57:14 -0700354 VideoSendStream::Stats send_stats = send_stream_->GetStats();
355
356 size_t total_packets_sent = 0;
357 size_t total_sent = 0;
358 size_t padding_sent = 0;
359 size_t media_sent = 0;
stefanff483612015-12-21 03:14:00 -0800360 for (uint32_t ssrc : video_ssrcs_) {
stefan092508a2015-09-29 02:26:42 -0700361 AccumulateStats(send_stats.substreams[ssrc], &total_packets_sent,
362 &total_sent, &padding_sent, &media_sent);
stefan4fbd1452015-09-28 03:57:14 -0700363 }
364
365 size_t rtx_total_packets_sent = 0;
366 size_t rtx_total_sent = 0;
367 size_t rtx_padding_sent = 0;
368 size_t rtx_media_sent = 0;
stefanff483612015-12-21 03:14:00 -0800369 for (uint32_t rtx_ssrc : video_rtx_ssrcs_) {
stefan092508a2015-09-29 02:26:42 -0700370 AccumulateStats(send_stats.substreams[rtx_ssrc], &rtx_total_packets_sent,
371 &rtx_total_sent, &rtx_padding_sent, &rtx_media_sent);
stefan4fbd1452015-09-28 03:57:14 -0700372 }
373
stefan5a2c5062017-01-27 06:43:18 -0800374 if (report_perf_stats_) {
stefan5a2c5062017-01-27 06:43:18 -0800375 ReportResult("ramp-up-media-sent", media_sent, "bytes");
376 ReportResult("ramp-up-padding-sent", padding_sent, "bytes");
stefan5a2c5062017-01-27 06:43:18 -0800377 ReportResult("ramp-up-rtx-media-sent", rtx_media_sent, "bytes");
378 ReportResult("ramp-up-rtx-padding-sent", rtx_padding_sent, "bytes");
379 if (ramp_up_finished_ms_ >= 0) {
380 ReportResult("ramp-up-time", ramp_up_finished_ms_ - test_start_ms_,
381 "milliseconds");
382 }
383 ReportResult("ramp-up-average-network-latency",
384 send_transport_->GetAverageDelayMs(), "milliseconds");
stefan4fbd1452015-09-28 03:57:14 -0700385 }
386}
387
388void RampUpTester::PerformTest() {
Erik Språngf3a7c9d2015-10-05 14:03:22 +0200389 test_start_ms_ = clock_->TimeInMilliseconds();
Peter Boström8c38e8b2015-11-26 17:45:47 +0100390 poller_thread_.Start();
Peter Boström5811a392015-12-10 13:02:50 +0100391 EXPECT_TRUE(Wait()) << "Timed out while waiting for ramp-up to complete.";
stefan4fbd1452015-09-28 03:57:14 -0700392 TriggerTestDone();
tommi0f8b4032017-02-22 11:22:05 -0800393 stop_event_.Set();
Peter Boström8c38e8b2015-11-26 17:45:47 +0100394 poller_thread_.Stop();
stefan4fbd1452015-09-28 03:57:14 -0700395}
396
Stefan Holmerff2a6352016-01-14 10:00:21 +0100397RampUpDownUpTester::RampUpDownUpTester(size_t num_video_streams,
398 size_t num_audio_streams,
philipel5ef2bc12017-02-21 07:28:31 -0800399 size_t num_flexfec_streams,
stefan4fbd1452015-09-28 03:57:14 -0700400 unsigned int start_bitrate_bps,
401 const std::string& extension_type,
402 bool rtx,
philipel5ef2bc12017-02-21 07:28:31 -0800403 bool red,
stefan45b5fe52017-03-09 06:27:02 -0800404 const std::vector<int>& loss_rates,
405 bool report_perf_stats)
Stefan Holmerff2a6352016-01-14 10:00:21 +0100406 : RampUpTester(num_video_streams,
407 num_audio_streams,
philipel5ef2bc12017-02-21 07:28:31 -0800408 num_flexfec_streams,
Stefan Holmerff2a6352016-01-14 10:00:21 +0100409 start_bitrate_bps,
stefan5a2c5062017-01-27 06:43:18 -0800410 0,
Stefan Holmerff2a6352016-01-14 10:00:21 +0100411 extension_type,
412 rtx,
stefan5a2c5062017-01-27 06:43:18 -0800413 red,
stefan45b5fe52017-03-09 06:27:02 -0800414 report_perf_stats),
stefan76d9c9c2017-04-01 06:51:09 -0700415 link_rates_({4 * GetExpectedHighBitrate() / (3 * 1000),
416 kLowBandwidthLimitBps / 1000,
417 4 * GetExpectedHighBitrate() / (3 * 1000), 0}),
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000418 test_state_(kFirstRampup),
philipel5ef2bc12017-02-21 07:28:31 -0800419 next_state_(kTransitionToNextState),
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000420 state_start_ms_(clock_->TimeInMilliseconds()),
stefan4fbd1452015-09-28 03:57:14 -0700421 interval_start_ms_(clock_->TimeInMilliseconds()),
philipel5ef2bc12017-02-21 07:28:31 -0800422 sent_bytes_(0),
423 loss_rates_(loss_rates) {
424 forward_transport_config_.link_capacity_kbps = link_rates_[test_state_];
425 forward_transport_config_.queue_delay_ms = 100;
426 forward_transport_config_.loss_percent = loss_rates_[test_state_];
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000427}
428
stefan4fbd1452015-09-28 03:57:14 -0700429RampUpDownUpTester::~RampUpDownUpTester() {}
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000430
tommi0f8b4032017-02-22 11:22:05 -0800431void RampUpDownUpTester::PollStats() {
432 do {
Alex Narest78609d52017-10-20 10:37:47 +0200433 int transmit_bitrate_bps = 0;
434 bool suspended = false;
435 if (num_video_streams_ > 0) {
tommi0f8b4032017-02-22 11:22:05 -0800436 webrtc::VideoSendStream::Stats stats = send_stream_->GetStats();
tommi0f8b4032017-02-22 11:22:05 -0800437 for (auto it : stats.substreams) {
438 transmit_bitrate_bps += it.second.total_bitrate_bps;
439 }
Alex Narest78609d52017-10-20 10:37:47 +0200440 suspended = stats.suspended;
441 }
442 if (num_audio_streams_ > 0 && sender_call_ != nullptr) {
tommi0f8b4032017-02-22 11:22:05 -0800443 // An audio send stream doesn't have bitrate stats, so the call send BW is
444 // currently used instead.
Alex Narest78609d52017-10-20 10:37:47 +0200445 transmit_bitrate_bps = sender_call_->GetStats().send_bandwidth_bps;
mflodman@webrtc.orgeb16b812014-06-16 08:57:39 +0000446 }
Alex Narest78609d52017-10-20 10:37:47 +0200447 EvolveTestState(transmit_bitrate_bps, suspended);
tommi0f8b4032017-02-22 11:22:05 -0800448 } while (!stop_event_.Wait(kPollIntervalMs));
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000449}
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000450
Sebastian Jansson72582242018-07-13 13:19:42 +0200451void RampUpDownUpTester::ModifyReceiverCallConfig(Call::Config* config) {
452 config->bitrate_config.min_bitrate_bps = 10000;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000453}
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000454
stefan4fbd1452015-09-28 03:57:14 -0700455std::string RampUpDownUpTester::GetModifierString() const {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000456 std::string str("_");
stefanff483612015-12-21 03:14:00 -0800457 if (num_video_streams_ > 0) {
Jonas Olsson0a713b62018-04-04 15:49:32 +0200458 str += rtc::ToString(num_video_streams_);
stefanff483612015-12-21 03:14:00 -0800459 str += "stream";
460 str += (num_video_streams_ > 1 ? "s" : "");
461 str += "_";
462 }
463 if (num_audio_streams_ > 0) {
Jonas Olsson0a713b62018-04-04 15:49:32 +0200464 str += rtc::ToString(num_audio_streams_);
stefanff483612015-12-21 03:14:00 -0800465 str += "stream";
466 str += (num_audio_streams_ > 1 ? "s" : "");
467 str += "_";
468 }
stefan4fbd1452015-09-28 03:57:14 -0700469 str += (rtx_ ? "" : "no");
Edward Lemurdd3987f2018-01-04 19:44:54 +0100470 str += "rtx_";
471 str += (red_ ? "" : "no");
472 str += "red";
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000473 return str;
474}
andresp@webrtc.orgc1480792014-03-20 03:23:55 +0000475
stefandb752f92016-12-05 08:23:40 -0800476int RampUpDownUpTester::GetExpectedHighBitrate() const {
stefan38d8b3c2017-01-09 04:19:24 -0800477 int expected_bitrate_bps = 0;
478 if (num_audio_streams_ > 0)
479 expected_bitrate_bps += kExpectedHighAudioBitrateBps;
480 if (num_video_streams_ > 0)
481 expected_bitrate_bps += kExpectedHighVideoBitrateBps;
482 return expected_bitrate_bps;
483}
484
philipel5ef2bc12017-02-21 07:28:31 -0800485size_t RampUpDownUpTester::GetFecBytes() const {
486 size_t flex_fec_bytes = 0;
487 if (num_flexfec_streams_ > 0) {
488 webrtc::VideoSendStream::Stats stats = send_stream_->GetStats();
489 for (const auto& kv : stats.substreams)
490 flex_fec_bytes += kv.second.rtp_stats.fec.TotalBytes();
491 }
492 return flex_fec_bytes;
493}
494
495bool RampUpDownUpTester::ExpectingFec() const {
496 return num_flexfec_streams_ > 0 && forward_transport_config_.loss_percent > 0;
497}
498
stefan4fbd1452015-09-28 03:57:14 -0700499void RampUpDownUpTester::EvolveTestState(int bitrate_bps, bool suspended) {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000500 int64_t now = clock_->TimeInMilliseconds();
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000501 switch (test_state_) {
philipel5ef2bc12017-02-21 07:28:31 -0800502 case kFirstRampup:
stefan4fbd1452015-09-28 03:57:14 -0700503 EXPECT_FALSE(suspended);
stefandb752f92016-12-05 08:23:40 -0800504 if (bitrate_bps >= GetExpectedHighBitrate()) {
stefan45b5fe52017-03-09 06:27:02 -0800505 if (report_perf_stats_) {
506 webrtc::test::PrintResult("ramp_up_down_up", GetModifierString(),
507 "first_rampup", now - state_start_ms_, "ms",
508 false);
509 }
philipel5ef2bc12017-02-21 07:28:31 -0800510 // Apply loss during the transition between states if FEC is enabled.
511 forward_transport_config_.loss_percent = loss_rates_[test_state_];
512 test_state_ = kTransitionToNextState;
513 next_state_ = kLowRate;
andresp@webrtc.orgc1480792014-03-20 03:23:55 +0000514 }
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000515 break;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000516 case kLowRate: {
mflodman86cc6ff2016-07-26 04:44:06 -0700517 // Audio streams are never suspended.
518 bool check_suspend_state = num_video_streams_ > 0;
Sebastian Jansson12fb1702018-02-23 11:34:18 +0100519 if (bitrate_bps < kLowBandwidthLimitBps + kLowBitrateMarginBps &&
mflodman86cc6ff2016-07-26 04:44:06 -0700520 suspended == check_suspend_state) {
stefan45b5fe52017-03-09 06:27:02 -0800521 if (report_perf_stats_) {
522 webrtc::test::PrintResult("ramp_up_down_up", GetModifierString(),
523 "rampdown", now - state_start_ms_, "ms",
524 false);
525 }
philipel5ef2bc12017-02-21 07:28:31 -0800526 // Apply loss during the transition between states if FEC is enabled.
527 forward_transport_config_.loss_percent = loss_rates_[test_state_];
528 test_state_ = kTransitionToNextState;
529 next_state_ = kSecondRampup;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000530 }
531 break;
532 }
philipel5ef2bc12017-02-21 07:28:31 -0800533 case kSecondRampup:
stefandb752f92016-12-05 08:23:40 -0800534 if (bitrate_bps >= GetExpectedHighBitrate() && !suspended) {
stefan45b5fe52017-03-09 06:27:02 -0800535 if (report_perf_stats_) {
536 webrtc::test::PrintResult("ramp_up_down_up", GetModifierString(),
537 "second_rampup", now - state_start_ms_,
538 "ms", false);
539 ReportResult("ramp-up-down-up-average-network-latency",
540 send_transport_->GetAverageDelayMs(), "milliseconds");
541 }
philipel5ef2bc12017-02-21 07:28:31 -0800542 // Apply loss during the transition between states if FEC is enabled.
543 forward_transport_config_.loss_percent = loss_rates_[test_state_];
544 test_state_ = kTransitionToNextState;
545 next_state_ = kTestEnd;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000546 }
547 break;
philipel5ef2bc12017-02-21 07:28:31 -0800548 case kTestEnd:
549 observation_complete_.Set();
550 break;
551 case kTransitionToNextState:
552 if (!ExpectingFec() || GetFecBytes() > 0) {
553 test_state_ = next_state_;
554 forward_transport_config_.link_capacity_kbps = link_rates_[test_state_];
555 // No loss while ramping up and down as it may affect the BWE
556 // negatively, making the test flaky.
557 forward_transport_config_.loss_percent = 0;
558 state_start_ms_ = now;
559 interval_start_ms_ = now;
560 sent_bytes_ = 0;
Artem Titov631cafa2018-08-21 21:01:00 +0200561 send_simulated_network_->SetConfig(forward_transport_config_);
philipel5ef2bc12017-02-21 07:28:31 -0800562 }
563 break;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000564 }
565}
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +0000566
stefan4fbd1452015-09-28 03:57:14 -0700567class RampUpTest : public test::CallTest {
Erik Språng6b8d3552015-09-24 15:06:57 +0200568 public:
stefan4fbd1452015-09-28 03:57:14 -0700569 RampUpTest() {}
Erik Språng6b8d3552015-09-24 15:06:57 +0200570};
571
Stefan Holmerff2a6352016-01-14 10:00:21 +0100572static const uint32_t kStartBitrateBps = 60000;
573
stefan38d8b3c2017-01-09 04:19:24 -0800574TEST_F(RampUpTest, UpDownUpAbsSendTimeSimulcastRedRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800575 std::vector<int> loss_rates = {0, 0, 0, 0};
576 RampUpDownUpTester test(3, 0, 0, kStartBitrateBps,
stefan45b5fe52017-03-09 06:27:02 -0800577 RtpExtension::kAbsSendTimeUri, true, true, loss_rates,
578 true);
stefane74eef12016-01-08 06:47:13 -0800579 RunBaseTest(&test);
Shao Changbine62202f2015-04-21 20:24:50 +0800580}
Stefan Holmerff2a6352016-01-14 10:00:21 +0100581
Taylor Brandstetterba6b5032018-02-16 09:59:56 -0800582// TODO(bugs.webrtc.org/8878)
583#if defined(WEBRTC_MAC)
584#define MAYBE_UpDownUpTransportSequenceNumberRtx \
585 DISABLED_UpDownUpTransportSequenceNumberRtx
586#else
587#define MAYBE_UpDownUpTransportSequenceNumberRtx \
588 UpDownUpTransportSequenceNumberRtx
589#endif
590TEST_F(RampUpTest, MAYBE_UpDownUpTransportSequenceNumberRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800591 std::vector<int> loss_rates = {0, 0, 0, 0};
592 RampUpDownUpTester test(3, 0, 0, kStartBitrateBps,
isheriff6f8d6862016-05-26 11:24:55 -0700593 RtpExtension::kTransportSequenceNumberUri, true,
stefan45b5fe52017-03-09 06:27:02 -0800594 false, loss_rates, true);
philipel5ef2bc12017-02-21 07:28:31 -0800595 RunBaseTest(&test);
596}
597
stefan45b5fe52017-03-09 06:27:02 -0800598// TODO(holmer): Tests which don't report perf stats should be moved to a
599// different executable since they per definition are not perf tests.
Taylor Brandstetter05d98222017-10-10 12:12:53 -0700600// This test is disabled because it crashes on Linux, and is flaky on other
601// platforms. See: crbug.com/webrtc/7919
602TEST_F(RampUpTest, DISABLED_UpDownUpTransportSequenceNumberPacketLoss) {
philipel5ef2bc12017-02-21 07:28:31 -0800603 std::vector<int> loss_rates = {20, 0, 0, 0};
604 RampUpDownUpTester test(1, 0, 1, kStartBitrateBps,
605 RtpExtension::kTransportSequenceNumberUri, true,
stefan45b5fe52017-03-09 06:27:02 -0800606 false, loss_rates, false);
Stefan Holmerff2a6352016-01-14 10:00:21 +0100607 RunBaseTest(&test);
608}
609
Taylor Brandstetterab86e7f2018-02-12 15:16:02 -0800610// TODO(bugs.webrtc.org/8878)
611#if defined(WEBRTC_MAC)
612#define MAYBE_UpDownUpAudioVideoTransportSequenceNumberRtx \
613 DISABLED_UpDownUpAudioVideoTransportSequenceNumberRtx
614#else
615#define MAYBE_UpDownUpAudioVideoTransportSequenceNumberRtx \
616 UpDownUpAudioVideoTransportSequenceNumberRtx
617#endif
618TEST_F(RampUpTest, MAYBE_UpDownUpAudioVideoTransportSequenceNumberRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800619 std::vector<int> loss_rates = {0, 0, 0, 0};
620 RampUpDownUpTester test(3, 1, 0, kStartBitrateBps,
isheriff6f8d6862016-05-26 11:24:55 -0700621 RtpExtension::kTransportSequenceNumberUri, true,
stefanff2ebf52017-03-13 01:27:03 -0700622 false, loss_rates, false);
Stefan Holmerff2a6352016-01-14 10:00:21 +0100623 RunBaseTest(&test);
624}
625
stefan38d8b3c2017-01-09 04:19:24 -0800626TEST_F(RampUpTest, UpDownUpAudioTransportSequenceNumberRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800627 std::vector<int> loss_rates = {0, 0, 0, 0};
628 RampUpDownUpTester test(0, 1, 0, kStartBitrateBps,
mflodman86cc6ff2016-07-26 04:44:06 -0700629 RtpExtension::kTransportSequenceNumberUri, true,
stefanff2ebf52017-03-13 01:27:03 -0700630 false, loss_rates, false);
mflodman86cc6ff2016-07-26 04:44:06 -0700631 RunBaseTest(&test);
632}
633
stefan38d8b3c2017-01-09 04:19:24 -0800634TEST_F(RampUpTest, TOffsetSimulcastRedRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800635 RampUpTester test(3, 0, 0, 0, 0, RtpExtension::kTimestampOffsetUri, true,
636 true, true);
stefan38d8b3c2017-01-09 04:19:24 -0800637 RunBaseTest(&test);
638}
639
640TEST_F(RampUpTest, AbsSendTime) {
philipel5ef2bc12017-02-21 07:28:31 -0800641 RampUpTester test(1, 0, 0, 0, 0, RtpExtension::kAbsSendTimeUri, false, false,
stefanff2ebf52017-03-13 01:27:03 -0700642 false);
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, AbsSendTimeSimulcastRedRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800647 RampUpTester test(3, 0, 0, 0, 0, RtpExtension::kAbsSendTimeUri, true, true,
stefan5a2c5062017-01-27 06:43:18 -0800648 true);
stefane74eef12016-01-08 06:47:13 -0800649 RunBaseTest(&test);
pbos@webrtc.org85bd53e2014-12-10 10:36:20 +0000650}
651
stefan38d8b3c2017-01-09 04:19:24 -0800652TEST_F(RampUpTest, TransportSequenceNumber) {
philipel5ef2bc12017-02-21 07:28:31 -0800653 RampUpTester test(1, 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
658TEST_F(RampUpTest, TransportSequenceNumberSimulcast) {
philipel5ef2bc12017-02-21 07:28:31 -0800659 RampUpTester test(3, 0, 0, 0, 0, RtpExtension::kTransportSequenceNumberUri,
stefanff2ebf52017-03-13 01:27:03 -0700660 false, false, false);
stefane74eef12016-01-08 06:47:13 -0800661 RunBaseTest(&test);
Erik Språng6b8d3552015-09-24 15:06:57 +0200662}
663
stefan38d8b3c2017-01-09 04:19:24 -0800664TEST_F(RampUpTest, TransportSequenceNumberSimulcastRedRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800665 RampUpTester test(3, 0, 0, 0, 0, RtpExtension::kTransportSequenceNumberUri,
stefan5a2c5062017-01-27 06:43:18 -0800666 true, true, true);
667 RunBaseTest(&test);
668}
669
Taylor Brandstetterab86e7f2018-02-12 15:16:02 -0800670// TODO(bugs.webrtc.org/8878)
671#if defined(WEBRTC_MAC)
672#define MAYBE_AudioTransportSequenceNumber DISABLED_AudioTransportSequenceNumber
673#else
674#define MAYBE_AudioTransportSequenceNumber AudioTransportSequenceNumber
675#endif
676TEST_F(RampUpTest, MAYBE_AudioTransportSequenceNumber) {
philipel5ef2bc12017-02-21 07:28:31 -0800677 RampUpTester test(0, 1, 0, 300000, 10000,
stefan5a2c5062017-01-27 06:43:18 -0800678 RtpExtension::kTransportSequenceNumberUri, false, false,
679 false);
stefane74eef12016-01-08 06:47:13 -0800680 RunBaseTest(&test);
Erik Språng6b8d3552015-09-24 15:06:57 +0200681}
pbos@webrtc.org744fbc72013-09-10 09:26:25 +0000682} // namespace webrtc