blob: 6ec3d836ab1dea14f37abaf4f8094ddbe46a936a [file] [log] [blame]
pbos@webrtc.org744fbc72013-09-10 09:26:25 +00001/*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
pbos@webrtc.org744fbc72013-09-10 09:26:25 +000010
stefanff483612015-12-21 03:14:00 -080011#include "webrtc/call/rampup_tests.h"
12
pbos@webrtc.org2b4ce3a2015-03-23 13:12:24 +000013#include "webrtc/base/checks.h"
philipel5ef2bc12017-02-21 07:28:31 -080014#include "webrtc/base/logging.h"
pbos12411ef2015-11-23 14:47:56 -080015#include "webrtc/base/platform_thread.h"
perkjfa10b552016-10-02 23:45:26 -070016#include "webrtc/test/encoder_settings.h"
kwibergac9f8762016-09-30 22:29:43 -070017#include "webrtc/test/gtest.h"
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +000018#include "webrtc/test/testsupport/perf_test.h"
pbos@webrtc.org744fbc72013-09-10 09:26:25 +000019
20namespace webrtc {
pbos@webrtc.org29023282013-09-11 10:14:56 +000021namespace {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000022
Stefan Holmer723dff12015-10-05 14:59:41 +020023static const int64_t kPollIntervalMs = 20;
philipel5ef2bc12017-02-21 07:28:31 -080024static const int kExpectedHighVideoBitrateBps = 80000;
stefandb752f92016-12-05 08:23:40 -080025static const int kExpectedHighAudioBitrateBps = 30000;
26static const int kLowBandwidthLimitBps = 20000;
27static const int kExpectedLowBitrateBps = 20000;
pbos@webrtc.org29023282013-09-11 10:14:56 +000028
stefanff483612015-12-21 03:14:00 -080029std::vector<uint32_t> GenerateSsrcs(size_t num_streams, uint32_t ssrc_offset) {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000030 std::vector<uint32_t> ssrcs;
31 for (size_t i = 0; i != num_streams; ++i)
32 ssrcs.push_back(static_cast<uint32_t>(ssrc_offset + i));
33 return ssrcs;
34}
mflodman@webrtc.orgeb16b812014-06-16 08:57:39 +000035} // namespace
henrik.lundin@webrtc.org845862f2014-03-06 07:19:28 +000036
stefanff483612015-12-21 03:14:00 -080037RampUpTester::RampUpTester(size_t num_video_streams,
38 size_t num_audio_streams,
philipel5ef2bc12017-02-21 07:28:31 -080039 size_t num_flexfec_streams,
stefan4fbd1452015-09-28 03:57:14 -070040 unsigned int start_bitrate_bps,
stefan5a2c5062017-01-27 06:43:18 -080041 int64_t min_run_time_ms,
stefan4fbd1452015-09-28 03:57:14 -070042 const std::string& extension_type,
43 bool rtx,
stefan5a2c5062017-01-27 06:43:18 -080044 bool red,
45 bool report_perf_stats)
stefan4fbd1452015-09-28 03:57:14 -070046 : EndToEndTest(test::CallTest::kLongTimeoutMs),
tommi0f8b4032017-02-22 11:22:05 -080047 stop_event_(false, false),
stefan4fbd1452015-09-28 03:57:14 -070048 clock_(Clock::GetRealTimeClock()),
stefanff483612015-12-21 03:14:00 -080049 num_video_streams_(num_video_streams),
50 num_audio_streams_(num_audio_streams),
philipel5ef2bc12017-02-21 07:28:31 -080051 num_flexfec_streams_(num_flexfec_streams),
stefan4fbd1452015-09-28 03:57:14 -070052 rtx_(rtx),
53 red_(red),
mflodman86cc6ff2016-07-26 04:44:06 -070054 sender_call_(nullptr),
stefan4fbd1452015-09-28 03:57:14 -070055 send_stream_(nullptr),
56 start_bitrate_bps_(start_bitrate_bps),
stefan5a2c5062017-01-27 06:43:18 -080057 min_run_time_ms_(min_run_time_ms),
58 report_perf_stats_(report_perf_stats),
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000059 expected_bitrate_bps_(0),
Erik Språngf3a7c9d2015-10-05 14:03:22 +020060 test_start_ms_(-1),
stefan4fbd1452015-09-28 03:57:14 -070061 ramp_up_finished_ms_(-1),
62 extension_type_(extension_type),
stefanff483612015-12-21 03:14:00 -080063 video_ssrcs_(GenerateSsrcs(num_video_streams_, 100)),
64 video_rtx_ssrcs_(GenerateSsrcs(num_video_streams_, 200)),
65 audio_ssrcs_(GenerateSsrcs(num_audio_streams_, 300)),
Peter Boström8c38e8b2015-11-26 17:45:47 +010066 poller_thread_(&BitrateStatsPollingThread,
67 this,
mflodman86cc6ff2016-07-26 04:44:06 -070068 "BitrateStatsPollingThread") {
philipel5ef2bc12017-02-21 07:28:31 -080069 if (red_)
70 EXPECT_EQ(0u, num_flexfec_streams_);
Stefan Holmerff2a6352016-01-14 10:00:21 +010071 EXPECT_LE(num_audio_streams_, 1u);
stefan4fbd1452015-09-28 03:57:14 -070072}
73
74RampUpTester::~RampUpTester() {
stefan4fbd1452015-09-28 03:57:14 -070075}
76
77Call::Config RampUpTester::GetSenderCallConfig() {
skvlad11a9cbf2016-10-07 11:53:05 -070078 Call::Config call_config(&event_log_);
stefan4fbd1452015-09-28 03:57:14 -070079 if (start_bitrate_bps_ != 0) {
80 call_config.bitrate_config.start_bitrate_bps = start_bitrate_bps_;
81 }
82 call_config.bitrate_config.min_bitrate_bps = 10000;
83 return call_config;
84}
85
stefanff483612015-12-21 03:14:00 -080086void RampUpTester::OnVideoStreamsCreated(
stefan4fbd1452015-09-28 03:57:14 -070087 VideoSendStream* send_stream,
88 const std::vector<VideoReceiveStream*>& receive_streams) {
89 send_stream_ = send_stream;
90}
91
stefane74eef12016-01-08 06:47:13 -080092test::PacketTransport* RampUpTester::CreateSendTransport(Call* sender_call) {
93 send_transport_ = new test::PacketTransport(sender_call, this,
94 test::PacketTransport::kSender,
95 forward_transport_config_);
96 return send_transport_;
stefanf116bd02015-10-27 08:29:42 -070097}
98
Stefan Holmerd20e6512016-01-12 15:51:22 +010099size_t RampUpTester::GetNumVideoStreams() const {
100 return num_video_streams_;
101}
102
Stefan Holmerff2a6352016-01-14 10:00:21 +0100103size_t RampUpTester::GetNumAudioStreams() const {
104 return num_audio_streams_;
105}
106
philipel5ef2bc12017-02-21 07:28:31 -0800107size_t RampUpTester::GetNumFlexfecStreams() const {
108 return num_flexfec_streams_;
109}
110
perkjfa10b552016-10-02 23:45:26 -0700111class RampUpTester::VideoStreamFactory
112 : public VideoEncoderConfig::VideoStreamFactoryInterface {
113 public:
114 VideoStreamFactory() {}
115
116 private:
117 std::vector<VideoStream> CreateEncoderStreams(
118 int width,
119 int height,
120 const VideoEncoderConfig& encoder_config) override {
121 std::vector<VideoStream> streams =
122 test::CreateVideoStreams(width, height, encoder_config);
123 if (encoder_config.number_of_streams == 1) {
124 streams[0].target_bitrate_bps = streams[0].max_bitrate_bps = 2000000;
125 }
126 return streams;
127 }
128};
129
stefanff483612015-12-21 03:14:00 -0800130void RampUpTester::ModifyVideoConfigs(
stefan4fbd1452015-09-28 03:57:14 -0700131 VideoSendStream::Config* send_config,
132 std::vector<VideoReceiveStream::Config>* receive_configs,
133 VideoEncoderConfig* encoder_config) {
134 send_config->suspend_below_min_bitrate = true;
perkjfa10b552016-10-02 23:45:26 -0700135 encoder_config->number_of_streams = num_video_streams_;
136 encoder_config->max_bitrate_bps = 2000000;
137 encoder_config->video_stream_factory =
138 new rtc::RefCountedObject<RampUpTester::VideoStreamFactory>();
stefanff483612015-12-21 03:14:00 -0800139 if (num_video_streams_ == 1) {
stefan4fbd1452015-09-28 03:57:14 -0700140 // For single stream rampup until 1mbps
141 expected_bitrate_bps_ = kSingleStreamTargetBps;
142 } else {
143 // For multi stream rampup until all streams are being sent. That means
perkjfa10b552016-10-02 23:45:26 -0700144 // enough bitrate to send all the target streams plus the min bitrate of
stefan4fbd1452015-09-28 03:57:14 -0700145 // the last one.
perkjfa10b552016-10-02 23:45:26 -0700146 std::vector<VideoStream> streams = test::CreateVideoStreams(
147 test::CallTest::kDefaultWidth, test::CallTest::kDefaultHeight,
148 *encoder_config);
149 expected_bitrate_bps_ = streams.back().min_bitrate_bps;
150 for (size_t i = 0; i < streams.size() - 1; ++i) {
151 expected_bitrate_bps_ += streams[i].target_bitrate_bps;
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000152 }
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000153 }
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000154
stefan4fbd1452015-09-28 03:57:14 -0700155 send_config->rtp.extensions.clear();
156
157 bool remb;
stefan43edf0f2015-11-20 18:05:48 -0800158 bool transport_cc;
isheriff6f8d6862016-05-26 11:24:55 -0700159 if (extension_type_ == RtpExtension::kAbsSendTimeUri) {
stefan4fbd1452015-09-28 03:57:14 -0700160 remb = true;
stefan43edf0f2015-11-20 18:05:48 -0800161 transport_cc = false;
stefan4fbd1452015-09-28 03:57:14 -0700162 send_config->rtp.extensions.push_back(
163 RtpExtension(extension_type_.c_str(), kAbsSendTimeExtensionId));
isheriff6f8d6862016-05-26 11:24:55 -0700164 } else if (extension_type_ == RtpExtension::kTransportSequenceNumberUri) {
stefan4fbd1452015-09-28 03:57:14 -0700165 remb = false;
stefan43edf0f2015-11-20 18:05:48 -0800166 transport_cc = true;
stefan4fbd1452015-09-28 03:57:14 -0700167 send_config->rtp.extensions.push_back(RtpExtension(
168 extension_type_.c_str(), kTransportSequenceNumberExtensionId));
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000169 } else {
stefan4fbd1452015-09-28 03:57:14 -0700170 remb = true;
stefan43edf0f2015-11-20 18:05:48 -0800171 transport_cc = false;
stefan4fbd1452015-09-28 03:57:14 -0700172 send_config->rtp.extensions.push_back(RtpExtension(
173 extension_type_.c_str(), kTransmissionTimeOffsetExtensionId));
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000174 }
stefan4fbd1452015-09-28 03:57:14 -0700175
176 send_config->rtp.nack.rtp_history_ms = test::CallTest::kNackRtpHistoryMs;
stefanff483612015-12-21 03:14:00 -0800177 send_config->rtp.ssrcs = video_ssrcs_;
stefan4fbd1452015-09-28 03:57:14 -0700178 if (rtx_) {
179 send_config->rtp.rtx.payload_type = test::CallTest::kSendRtxPayloadType;
stefanff483612015-12-21 03:14:00 -0800180 send_config->rtp.rtx.ssrcs = video_rtx_ssrcs_;
stefan4fbd1452015-09-28 03:57:14 -0700181 }
182 if (red_) {
brandtrb5f2c3f2016-10-04 23:28:39 -0700183 send_config->rtp.ulpfec.ulpfec_payload_type =
stefan4fbd1452015-09-28 03:57:14 -0700184 test::CallTest::kUlpfecPayloadType;
brandtrb5f2c3f2016-10-04 23:28:39 -0700185 send_config->rtp.ulpfec.red_payload_type = test::CallTest::kRedPayloadType;
brandtrfbfb5362016-11-17 04:18:37 -0800186 if (rtx_) {
187 send_config->rtp.ulpfec.red_rtx_payload_type =
188 test::CallTest::kRtxRedPayloadType;
189 }
stefan4fbd1452015-09-28 03:57:14 -0700190 }
191
192 size_t i = 0;
193 for (VideoReceiveStream::Config& recv_config : *receive_configs) {
194 recv_config.rtp.remb = remb;
stefan43edf0f2015-11-20 18:05:48 -0800195 recv_config.rtp.transport_cc = transport_cc;
stefan4fbd1452015-09-28 03:57:14 -0700196 recv_config.rtp.extensions = send_config->rtp.extensions;
197
stefanff483612015-12-21 03:14:00 -0800198 recv_config.rtp.remote_ssrc = video_ssrcs_[i];
stefan4fbd1452015-09-28 03:57:14 -0700199 recv_config.rtp.nack.rtp_history_ms = send_config->rtp.nack.rtp_history_ms;
200
201 if (red_) {
brandtrb5f2c3f2016-10-04 23:28:39 -0700202 recv_config.rtp.ulpfec.red_payload_type =
203 send_config->rtp.ulpfec.red_payload_type;
204 recv_config.rtp.ulpfec.ulpfec_payload_type =
205 send_config->rtp.ulpfec.ulpfec_payload_type;
brandtrfbfb5362016-11-17 04:18:37 -0800206 if (rtx_) {
207 recv_config.rtp.ulpfec.red_rtx_payload_type =
208 send_config->rtp.ulpfec.red_rtx_payload_type;
209 }
stefan4fbd1452015-09-28 03:57:14 -0700210 }
211
212 if (rtx_) {
brandtr14742122017-01-27 04:53:07 -0800213 recv_config.rtp.rtx_ssrc = video_rtx_ssrcs_[i];
214 recv_config.rtp
215 .rtx_payload_types[send_config->encoder_settings.payload_type] =
216 send_config->rtp.rtx.payload_type;
stefan4fbd1452015-09-28 03:57:14 -0700217 }
218 ++i;
219 }
philipel5ef2bc12017-02-21 07:28:31 -0800220
221 RTC_DCHECK_LE(num_flexfec_streams_, 1);
222 if (num_flexfec_streams_ == 1) {
223 send_config->rtp.flexfec.payload_type = test::CallTest::kFlexfecPayloadType;
224 send_config->rtp.flexfec.ssrc = test::CallTest::kFlexfecSendSsrc;
225 send_config->rtp.flexfec.protected_media_ssrcs = {video_ssrcs_[0]};
226 }
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000227}
228
Stefan Holmerff2a6352016-01-14 10:00:21 +0100229void RampUpTester::ModifyAudioConfigs(
230 AudioSendStream::Config* send_config,
231 std::vector<AudioReceiveStream::Config>* receive_configs) {
232 if (num_audio_streams_ == 0)
233 return;
234
isheriff6f8d6862016-05-26 11:24:55 -0700235 EXPECT_NE(RtpExtension::kTimestampOffsetUri, extension_type_)
Stefan Holmerff2a6352016-01-14 10:00:21 +0100236 << "Audio BWE not supported with toffset.";
philipel5ef2bc12017-02-21 07:28:31 -0800237 EXPECT_NE(RtpExtension::kAbsSendTimeUri, extension_type_)
238 << "Audio BWE not supported with abs-send-time.";
Stefan Holmerff2a6352016-01-14 10:00:21 +0100239
240 send_config->rtp.ssrc = audio_ssrcs_[0];
241 send_config->rtp.extensions.clear();
242
minyue10cbb462016-11-07 09:29:22 -0800243 send_config->min_bitrate_bps = 6000;
244 send_config->max_bitrate_bps = 60000;
mflodman86cc6ff2016-07-26 04:44:06 -0700245
Stefan Holmerff2a6352016-01-14 10:00:21 +0100246 bool transport_cc = false;
philipel5ef2bc12017-02-21 07:28:31 -0800247 if (extension_type_ == RtpExtension::kTransportSequenceNumberUri) {
Stefan Holmerff2a6352016-01-14 10:00:21 +0100248 transport_cc = true;
249 send_config->rtp.extensions.push_back(RtpExtension(
250 extension_type_.c_str(), kTransportSequenceNumberExtensionId));
251 }
252
253 for (AudioReceiveStream::Config& recv_config : *receive_configs) {
Stefan Holmerff2a6352016-01-14 10:00:21 +0100254 recv_config.rtp.transport_cc = transport_cc;
255 recv_config.rtp.extensions = send_config->rtp.extensions;
256 recv_config.rtp.remote_ssrc = send_config->rtp.ssrc;
257 }
258}
259
philipel5ef2bc12017-02-21 07:28:31 -0800260void RampUpTester::ModifyFlexfecConfigs(
261 std::vector<FlexfecReceiveStream::Config>* receive_configs) {
262 if (num_flexfec_streams_ == 0)
263 return;
264 RTC_DCHECK_EQ(1, num_flexfec_streams_);
265 (*receive_configs)[0].payload_type = test::CallTest::kFlexfecPayloadType;
266 (*receive_configs)[0].remote_ssrc = test::CallTest::kFlexfecSendSsrc;
267 (*receive_configs)[0].protected_media_ssrcs = {video_ssrcs_[0]};
268 (*receive_configs)[0].local_ssrc = video_ssrcs_[0];
269 if (extension_type_ == RtpExtension::kAbsSendTimeUri) {
270 (*receive_configs)[0].transport_cc = false;
271 (*receive_configs)[0].rtp_header_extensions.push_back(
272 RtpExtension(extension_type_.c_str(), kAbsSendTimeExtensionId));
273 } else if (extension_type_ == RtpExtension::kTransportSequenceNumberUri) {
274 (*receive_configs)[0].transport_cc = true;
275 (*receive_configs)[0].rtp_header_extensions.push_back(RtpExtension(
276 extension_type_.c_str(), kTransportSequenceNumberExtensionId));
277 }
278}
279
stefan4fbd1452015-09-28 03:57:14 -0700280void RampUpTester::OnCallsCreated(Call* sender_call, Call* receiver_call) {
281 sender_call_ = sender_call;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000282}
283
tommi0f8b4032017-02-22 11:22:05 -0800284void RampUpTester::BitrateStatsPollingThread(void* obj) {
285 static_cast<RampUpTester*>(obj)->PollStats();
pbos@webrtc.org32452b22014-10-22 12:15:24 +0000286}
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000287
tommi0f8b4032017-02-22 11:22:05 -0800288void RampUpTester::PollStats() {
289 do {
290 if (sender_call_) {
291 Call::Stats stats = sender_call_->GetStats();
stefan4fbd1452015-09-28 03:57:14 -0700292
tommi0f8b4032017-02-22 11:22:05 -0800293 EXPECT_GE(stats.send_bandwidth_bps, start_bitrate_bps_);
294 EXPECT_GE(expected_bitrate_bps_, 0);
295 if (stats.send_bandwidth_bps >= expected_bitrate_bps_ &&
296 (min_run_time_ms_ == -1 ||
297 clock_->TimeInMilliseconds() - test_start_ms_ >= min_run_time_ms_)) {
298 ramp_up_finished_ms_ = clock_->TimeInMilliseconds();
299 observation_complete_.Set();
300 }
stefan4fbd1452015-09-28 03:57:14 -0700301 }
tommi0f8b4032017-02-22 11:22:05 -0800302 } while (!stop_event_.Wait(kPollIntervalMs));
Erik Språng468e62a2015-07-06 10:50:47 +0200303}
304
stefan4fbd1452015-09-28 03:57:14 -0700305void RampUpTester::ReportResult(const std::string& measurement,
306 size_t value,
307 const std::string& units) const {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000308 webrtc::test::PrintResult(
309 measurement, "",
stefanff483612015-12-21 03:14:00 -0800310 ::testing::UnitTest::GetInstance()->current_test_info()->name(), value,
311 units, false);
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000312}
313
stefan092508a2015-09-29 02:26:42 -0700314void RampUpTester::AccumulateStats(const VideoSendStream::StreamStats& stream,
315 size_t* total_packets_sent,
316 size_t* total_sent,
317 size_t* padding_sent,
318 size_t* media_sent) const {
stefan4fbd1452015-09-28 03:57:14 -0700319 *total_packets_sent += stream.rtp_stats.transmitted.packets +
320 stream.rtp_stats.retransmitted.packets +
321 stream.rtp_stats.fec.packets;
322 *total_sent += stream.rtp_stats.transmitted.TotalBytes() +
323 stream.rtp_stats.retransmitted.TotalBytes() +
324 stream.rtp_stats.fec.TotalBytes();
325 *padding_sent += stream.rtp_stats.transmitted.padding_bytes +
326 stream.rtp_stats.retransmitted.padding_bytes +
327 stream.rtp_stats.fec.padding_bytes;
328 *media_sent += stream.rtp_stats.MediaPayloadBytes();
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000329}
330
stefan4fbd1452015-09-28 03:57:14 -0700331void RampUpTester::TriggerTestDone() {
Erik Språngf3a7c9d2015-10-05 14:03:22 +0200332 RTC_DCHECK_GE(test_start_ms_, 0);
333
Stefan Holmerff2a6352016-01-14 10:00:21 +0100334 // TODO(holmer): Add audio send stats here too when those APIs are available.
mflodman86cc6ff2016-07-26 04:44:06 -0700335 if (!send_stream_)
336 return;
337
stefan4fbd1452015-09-28 03:57:14 -0700338 VideoSendStream::Stats send_stats = send_stream_->GetStats();
339
340 size_t total_packets_sent = 0;
341 size_t total_sent = 0;
342 size_t padding_sent = 0;
343 size_t media_sent = 0;
stefanff483612015-12-21 03:14:00 -0800344 for (uint32_t ssrc : video_ssrcs_) {
stefan092508a2015-09-29 02:26:42 -0700345 AccumulateStats(send_stats.substreams[ssrc], &total_packets_sent,
346 &total_sent, &padding_sent, &media_sent);
stefan4fbd1452015-09-28 03:57:14 -0700347 }
348
349 size_t rtx_total_packets_sent = 0;
350 size_t rtx_total_sent = 0;
351 size_t rtx_padding_sent = 0;
352 size_t rtx_media_sent = 0;
stefanff483612015-12-21 03:14:00 -0800353 for (uint32_t rtx_ssrc : video_rtx_ssrcs_) {
stefan092508a2015-09-29 02:26:42 -0700354 AccumulateStats(send_stats.substreams[rtx_ssrc], &rtx_total_packets_sent,
355 &rtx_total_sent, &rtx_padding_sent, &rtx_media_sent);
stefan4fbd1452015-09-28 03:57:14 -0700356 }
357
stefan5a2c5062017-01-27 06:43:18 -0800358 if (report_perf_stats_) {
359 ReportResult("ramp-up-total-packets-sent", total_packets_sent, "packets");
360 ReportResult("ramp-up-total-sent", total_sent, "bytes");
361 ReportResult("ramp-up-media-sent", media_sent, "bytes");
362 ReportResult("ramp-up-padding-sent", padding_sent, "bytes");
363 ReportResult("ramp-up-rtx-total-packets-sent", rtx_total_packets_sent,
364 "packets");
365 ReportResult("ramp-up-rtx-total-sent", rtx_total_sent, "bytes");
366 ReportResult("ramp-up-rtx-media-sent", rtx_media_sent, "bytes");
367 ReportResult("ramp-up-rtx-padding-sent", rtx_padding_sent, "bytes");
368 if (ramp_up_finished_ms_ >= 0) {
369 ReportResult("ramp-up-time", ramp_up_finished_ms_ - test_start_ms_,
370 "milliseconds");
371 }
372 ReportResult("ramp-up-average-network-latency",
373 send_transport_->GetAverageDelayMs(), "milliseconds");
stefan4fbd1452015-09-28 03:57:14 -0700374 }
375}
376
377void RampUpTester::PerformTest() {
Erik Språngf3a7c9d2015-10-05 14:03:22 +0200378 test_start_ms_ = clock_->TimeInMilliseconds();
Peter Boström8c38e8b2015-11-26 17:45:47 +0100379 poller_thread_.Start();
Peter Boström5811a392015-12-10 13:02:50 +0100380 EXPECT_TRUE(Wait()) << "Timed out while waiting for ramp-up to complete.";
stefan4fbd1452015-09-28 03:57:14 -0700381 TriggerTestDone();
tommi0f8b4032017-02-22 11:22:05 -0800382 stop_event_.Set();
Peter Boström8c38e8b2015-11-26 17:45:47 +0100383 poller_thread_.Stop();
stefan4fbd1452015-09-28 03:57:14 -0700384}
385
Stefan Holmerff2a6352016-01-14 10:00:21 +0100386RampUpDownUpTester::RampUpDownUpTester(size_t num_video_streams,
387 size_t num_audio_streams,
philipel5ef2bc12017-02-21 07:28:31 -0800388 size_t num_flexfec_streams,
stefan4fbd1452015-09-28 03:57:14 -0700389 unsigned int start_bitrate_bps,
390 const std::string& extension_type,
391 bool rtx,
philipel5ef2bc12017-02-21 07:28:31 -0800392 bool red,
393 const std::vector<int>& loss_rates)
Stefan Holmerff2a6352016-01-14 10:00:21 +0100394 : RampUpTester(num_video_streams,
395 num_audio_streams,
philipel5ef2bc12017-02-21 07:28:31 -0800396 num_flexfec_streams,
Stefan Holmerff2a6352016-01-14 10:00:21 +0100397 start_bitrate_bps,
stefan5a2c5062017-01-27 06:43:18 -0800398 0,
Stefan Holmerff2a6352016-01-14 10:00:21 +0100399 extension_type,
400 rtx,
stefan5a2c5062017-01-27 06:43:18 -0800401 red,
402 true),
philipel5ef2bc12017-02-21 07:28:31 -0800403 link_rates_({GetHighLinkCapacity(), kLowBandwidthLimitBps / 1000,
404 GetHighLinkCapacity(), 0}),
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000405 test_state_(kFirstRampup),
philipel5ef2bc12017-02-21 07:28:31 -0800406 next_state_(kTransitionToNextState),
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000407 state_start_ms_(clock_->TimeInMilliseconds()),
stefan4fbd1452015-09-28 03:57:14 -0700408 interval_start_ms_(clock_->TimeInMilliseconds()),
philipel5ef2bc12017-02-21 07:28:31 -0800409 sent_bytes_(0),
410 loss_rates_(loss_rates) {
411 forward_transport_config_.link_capacity_kbps = link_rates_[test_state_];
412 forward_transport_config_.queue_delay_ms = 100;
413 forward_transport_config_.loss_percent = loss_rates_[test_state_];
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000414}
415
stefan4fbd1452015-09-28 03:57:14 -0700416RampUpDownUpTester::~RampUpDownUpTester() {}
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000417
tommi0f8b4032017-02-22 11:22:05 -0800418void RampUpDownUpTester::PollStats() {
419 do {
420 if (send_stream_) {
421 webrtc::VideoSendStream::Stats stats = send_stream_->GetStats();
422 int transmit_bitrate_bps = 0;
423 for (auto it : stats.substreams) {
424 transmit_bitrate_bps += it.second.total_bitrate_bps;
425 }
426 EvolveTestState(transmit_bitrate_bps, stats.suspended);
427 } else if (num_audio_streams_ > 0 && sender_call_ != nullptr) {
428 // An audio send stream doesn't have bitrate stats, so the call send BW is
429 // currently used instead.
430 int transmit_bitrate_bps = sender_call_->GetStats().send_bandwidth_bps;
431 EvolveTestState(transmit_bitrate_bps, false);
mflodman@webrtc.orgeb16b812014-06-16 08:57:39 +0000432 }
tommi0f8b4032017-02-22 11:22:05 -0800433 } while (!stop_event_.Wait(kPollIntervalMs));
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000434}
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000435
stefan4fbd1452015-09-28 03:57:14 -0700436Call::Config RampUpDownUpTester::GetReceiverCallConfig() {
skvlad11a9cbf2016-10-07 11:53:05 -0700437 Call::Config config(&event_log_);
stefan4fbd1452015-09-28 03:57:14 -0700438 config.bitrate_config.min_bitrate_bps = 10000;
439 return config;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000440}
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000441
stefan4fbd1452015-09-28 03:57:14 -0700442std::string RampUpDownUpTester::GetModifierString() const {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000443 std::string str("_");
stefanff483612015-12-21 03:14:00 -0800444 if (num_video_streams_ > 0) {
445 std::ostringstream s;
446 s << num_video_streams_;
447 str += s.str();
448 str += "stream";
449 str += (num_video_streams_ > 1 ? "s" : "");
450 str += "_";
451 }
452 if (num_audio_streams_ > 0) {
453 std::ostringstream s;
454 s << num_audio_streams_;
455 str += s.str();
456 str += "stream";
457 str += (num_audio_streams_ > 1 ? "s" : "");
458 str += "_";
459 }
stefan4fbd1452015-09-28 03:57:14 -0700460 str += (rtx_ ? "" : "no");
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000461 str += "rtx";
462 return str;
463}
andresp@webrtc.orgc1480792014-03-20 03:23:55 +0000464
stefandb752f92016-12-05 08:23:40 -0800465int RampUpDownUpTester::GetExpectedHighBitrate() const {
stefan38d8b3c2017-01-09 04:19:24 -0800466 int expected_bitrate_bps = 0;
467 if (num_audio_streams_ > 0)
468 expected_bitrate_bps += kExpectedHighAudioBitrateBps;
469 if (num_video_streams_ > 0)
470 expected_bitrate_bps += kExpectedHighVideoBitrateBps;
471 return expected_bitrate_bps;
472}
473
474int RampUpDownUpTester::GetHighLinkCapacity() const {
475 return 4 * GetExpectedHighBitrate() / (3 * 1000);
stefandb752f92016-12-05 08:23:40 -0800476}
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()) {
stefanff483612015-12-21 03:14:00 -0800498 webrtc::test::PrintResult("ramp_up_down_up", GetModifierString(),
499 "first_rampup", now - state_start_ms_, "ms",
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000500 false);
philipel5ef2bc12017-02-21 07:28:31 -0800501 // Apply loss during the transition between states if FEC is enabled.
502 forward_transport_config_.loss_percent = loss_rates_[test_state_];
503 test_state_ = kTransitionToNextState;
504 next_state_ = kLowRate;
andresp@webrtc.orgc1480792014-03-20 03:23:55 +0000505 }
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000506 break;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000507 case kLowRate: {
mflodman86cc6ff2016-07-26 04:44:06 -0700508 // Audio streams are never suspended.
509 bool check_suspend_state = num_video_streams_ > 0;
510 if (bitrate_bps < kExpectedLowBitrateBps &&
511 suspended == check_suspend_state) {
stefanff483612015-12-21 03:14:00 -0800512 webrtc::test::PrintResult("ramp_up_down_up", GetModifierString(),
513 "rampdown", now - state_start_ms_, "ms",
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000514 false);
philipel5ef2bc12017-02-21 07:28:31 -0800515 // Apply loss during the transition between states if FEC is enabled.
516 forward_transport_config_.loss_percent = loss_rates_[test_state_];
517 test_state_ = kTransitionToNextState;
518 next_state_ = kSecondRampup;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000519 }
520 break;
521 }
philipel5ef2bc12017-02-21 07:28:31 -0800522 case kSecondRampup:
stefandb752f92016-12-05 08:23:40 -0800523 if (bitrate_bps >= GetExpectedHighBitrate() && !suspended) {
stefanff483612015-12-21 03:14:00 -0800524 webrtc::test::PrintResult("ramp_up_down_up", GetModifierString(),
525 "second_rampup", now - state_start_ms_, "ms",
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000526 false);
Stefan Holmerff2a6352016-01-14 10:00:21 +0100527 ReportResult("ramp-up-down-up-average-network-latency",
528 send_transport_->GetAverageDelayMs(), "milliseconds");
philipel5ef2bc12017-02-21 07:28:31 -0800529 // Apply loss during the transition between states if FEC is enabled.
530 forward_transport_config_.loss_percent = loss_rates_[test_state_];
531 test_state_ = kTransitionToNextState;
532 next_state_ = kTestEnd;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000533 }
534 break;
philipel5ef2bc12017-02-21 07:28:31 -0800535 case kTestEnd:
536 observation_complete_.Set();
537 break;
538 case kTransitionToNextState:
539 if (!ExpectingFec() || GetFecBytes() > 0) {
540 test_state_ = next_state_;
541 forward_transport_config_.link_capacity_kbps = link_rates_[test_state_];
542 // No loss while ramping up and down as it may affect the BWE
543 // negatively, making the test flaky.
544 forward_transport_config_.loss_percent = 0;
545 state_start_ms_ = now;
546 interval_start_ms_ = now;
547 sent_bytes_ = 0;
548 send_transport_->SetConfig(forward_transport_config_);
549 }
550 break;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000551 }
552}
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +0000553
stefan4fbd1452015-09-28 03:57:14 -0700554class RampUpTest : public test::CallTest {
Erik Språng6b8d3552015-09-24 15:06:57 +0200555 public:
stefan4fbd1452015-09-28 03:57:14 -0700556 RampUpTest() {}
Erik Språng6b8d3552015-09-24 15:06:57 +0200557
stefan4fbd1452015-09-28 03:57:14 -0700558 virtual ~RampUpTest() {
stefanff483612015-12-21 03:14:00 -0800559 EXPECT_EQ(nullptr, video_send_stream_);
560 EXPECT_TRUE(video_receive_streams_.empty());
Erik Språng6b8d3552015-09-24 15:06:57 +0200561 }
Erik Språng6b8d3552015-09-24 15:06:57 +0200562};
563
Stefan Holmerff2a6352016-01-14 10:00:21 +0100564static const uint32_t kStartBitrateBps = 60000;
565
stefan38d8b3c2017-01-09 04:19:24 -0800566TEST_F(RampUpTest, UpDownUpAbsSendTimeSimulcastRedRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800567 std::vector<int> loss_rates = {0, 0, 0, 0};
568 RampUpDownUpTester test(3, 0, 0, kStartBitrateBps,
569 RtpExtension::kAbsSendTimeUri, true, true,
570 loss_rates);
stefane74eef12016-01-08 06:47:13 -0800571 RunBaseTest(&test);
Shao Changbine62202f2015-04-21 20:24:50 +0800572}
Stefan Holmerff2a6352016-01-14 10:00:21 +0100573
stefan38d8b3c2017-01-09 04:19:24 -0800574TEST_F(RampUpTest, UpDownUpTransportSequenceNumberRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800575 std::vector<int> loss_rates = {0, 0, 0, 0};
576 RampUpDownUpTester test(3, 0, 0, kStartBitrateBps,
isheriff6f8d6862016-05-26 11:24:55 -0700577 RtpExtension::kTransportSequenceNumberUri, true,
philipel5ef2bc12017-02-21 07:28:31 -0800578 false, loss_rates);
579 RunBaseTest(&test);
580}
581
582TEST_F(RampUpTest, UpDownUpTransportSequenceNumberPacketLoss) {
583 std::vector<int> loss_rates = {20, 0, 0, 0};
584 RampUpDownUpTester test(1, 0, 1, kStartBitrateBps,
585 RtpExtension::kTransportSequenceNumberUri, true,
586 false, loss_rates);
Stefan Holmerff2a6352016-01-14 10:00:21 +0100587 RunBaseTest(&test);
588}
589
stefan38d8b3c2017-01-09 04:19:24 -0800590TEST_F(RampUpTest, UpDownUpAudioVideoTransportSequenceNumberRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800591 std::vector<int> loss_rates = {0, 0, 0, 0};
592 RampUpDownUpTester test(3, 1, 0, kStartBitrateBps,
isheriff6f8d6862016-05-26 11:24:55 -0700593 RtpExtension::kTransportSequenceNumberUri, true,
philipel5ef2bc12017-02-21 07:28:31 -0800594 false, loss_rates);
Stefan Holmerff2a6352016-01-14 10:00:21 +0100595 RunBaseTest(&test);
596}
597
stefan38d8b3c2017-01-09 04:19:24 -0800598TEST_F(RampUpTest, UpDownUpAudioTransportSequenceNumberRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800599 std::vector<int> loss_rates = {0, 0, 0, 0};
600 RampUpDownUpTester test(0, 1, 0, kStartBitrateBps,
mflodman86cc6ff2016-07-26 04:44:06 -0700601 RtpExtension::kTransportSequenceNumberUri, true,
philipel5ef2bc12017-02-21 07:28:31 -0800602 false, loss_rates);
mflodman86cc6ff2016-07-26 04:44:06 -0700603 RunBaseTest(&test);
604}
605
stefan38d8b3c2017-01-09 04:19:24 -0800606TEST_F(RampUpTest, TOffsetSimulcastRedRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800607 RampUpTester test(3, 0, 0, 0, 0, RtpExtension::kTimestampOffsetUri, true,
608 true, true);
stefan38d8b3c2017-01-09 04:19:24 -0800609 RunBaseTest(&test);
610}
611
612TEST_F(RampUpTest, AbsSendTime) {
philipel5ef2bc12017-02-21 07:28:31 -0800613 RampUpTester test(1, 0, 0, 0, 0, RtpExtension::kAbsSendTimeUri, false, false,
stefan5a2c5062017-01-27 06:43:18 -0800614 true);
stefane74eef12016-01-08 06:47:13 -0800615 RunBaseTest(&test);
pbos@webrtc.org85bd53e2014-12-10 10:36:20 +0000616}
617
stefan38d8b3c2017-01-09 04:19:24 -0800618TEST_F(RampUpTest, AbsSendTimeSimulcastRedRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800619 RampUpTester test(3, 0, 0, 0, 0, RtpExtension::kAbsSendTimeUri, true, true,
stefan5a2c5062017-01-27 06:43:18 -0800620 true);
stefane74eef12016-01-08 06:47:13 -0800621 RunBaseTest(&test);
pbos@webrtc.org85bd53e2014-12-10 10:36:20 +0000622}
623
stefan38d8b3c2017-01-09 04:19:24 -0800624TEST_F(RampUpTest, TransportSequenceNumber) {
philipel5ef2bc12017-02-21 07:28:31 -0800625 RampUpTester test(1, 0, 0, 0, 0, RtpExtension::kTransportSequenceNumberUri,
stefan5a2c5062017-01-27 06:43:18 -0800626 false, false, true);
stefane74eef12016-01-08 06:47:13 -0800627 RunBaseTest(&test);
Erik Språng6b8d3552015-09-24 15:06:57 +0200628}
629
630TEST_F(RampUpTest, TransportSequenceNumberSimulcast) {
philipel5ef2bc12017-02-21 07:28:31 -0800631 RampUpTester test(3, 0, 0, 0, 0, RtpExtension::kTransportSequenceNumberUri,
stefan5a2c5062017-01-27 06:43:18 -0800632 false, false, true);
stefane74eef12016-01-08 06:47:13 -0800633 RunBaseTest(&test);
Erik Språng6b8d3552015-09-24 15:06:57 +0200634}
635
stefan38d8b3c2017-01-09 04:19:24 -0800636TEST_F(RampUpTest, TransportSequenceNumberSimulcastRedRtx) {
philipel5ef2bc12017-02-21 07:28:31 -0800637 RampUpTester test(3, 0, 0, 0, 0, RtpExtension::kTransportSequenceNumberUri,
stefan5a2c5062017-01-27 06:43:18 -0800638 true, true, true);
639 RunBaseTest(&test);
640}
641
642TEST_F(RampUpTest, AudioTransportSequenceNumber) {
philipel5ef2bc12017-02-21 07:28:31 -0800643 RampUpTester test(0, 1, 0, 300000, 10000,
stefan5a2c5062017-01-27 06:43:18 -0800644 RtpExtension::kTransportSequenceNumberUri, false, false,
645 false);
stefane74eef12016-01-08 06:47:13 -0800646 RunBaseTest(&test);
Erik Språng6b8d3552015-09-24 15:06:57 +0200647}
pbos@webrtc.org744fbc72013-09-10 09:26:25 +0000648} // namespace webrtc