blob: 320d22de64daaea18ca0f9b77409f463826eace7 [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.org744fbc72013-09-10 09:26:25 +000013#include "testing/gtest/include/gtest/gtest.h"
pbos@webrtc.org2b4ce3a2015-03-23 13:12:24 +000014#include "webrtc/base/checks.h"
pbos12411ef2015-11-23 14:47:56 -080015#include "webrtc/base/platform_thread.h"
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +000016#include "webrtc/test/testsupport/perf_test.h"
pbos@webrtc.org744fbc72013-09-10 09:26:25 +000017
18namespace webrtc {
pbos@webrtc.org29023282013-09-11 10:14:56 +000019namespace {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000020
Stefan Holmer723dff12015-10-05 14:59:41 +020021static const int64_t kPollIntervalMs = 20;
pbos@webrtc.org29023282013-09-11 10:14:56 +000022
stefanff483612015-12-21 03:14:00 -080023std::vector<uint32_t> GenerateSsrcs(size_t num_streams, uint32_t ssrc_offset) {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000024 std::vector<uint32_t> ssrcs;
25 for (size_t i = 0; i != num_streams; ++i)
26 ssrcs.push_back(static_cast<uint32_t>(ssrc_offset + i));
27 return ssrcs;
28}
mflodman@webrtc.orgeb16b812014-06-16 08:57:39 +000029} // namespace
henrik.lundin@webrtc.org845862f2014-03-06 07:19:28 +000030
stefanff483612015-12-21 03:14:00 -080031RampUpTester::RampUpTester(size_t num_video_streams,
32 size_t num_audio_streams,
stefan4fbd1452015-09-28 03:57:14 -070033 unsigned int start_bitrate_bps,
34 const std::string& extension_type,
35 bool rtx,
36 bool red)
37 : EndToEndTest(test::CallTest::kLongTimeoutMs),
38 event_(false, false),
39 clock_(Clock::GetRealTimeClock()),
stefanff483612015-12-21 03:14:00 -080040 num_video_streams_(num_video_streams),
41 num_audio_streams_(num_audio_streams),
stefan4fbd1452015-09-28 03:57:14 -070042 rtx_(rtx),
43 red_(red),
mflodman86cc6ff2016-07-26 04:44:06 -070044 sender_call_(nullptr),
stefan4fbd1452015-09-28 03:57:14 -070045 send_stream_(nullptr),
46 start_bitrate_bps_(start_bitrate_bps),
47 start_bitrate_verified_(false),
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000048 expected_bitrate_bps_(0),
Erik Språngf3a7c9d2015-10-05 14:03:22 +020049 test_start_ms_(-1),
stefan4fbd1452015-09-28 03:57:14 -070050 ramp_up_finished_ms_(-1),
51 extension_type_(extension_type),
stefanff483612015-12-21 03:14:00 -080052 video_ssrcs_(GenerateSsrcs(num_video_streams_, 100)),
53 video_rtx_ssrcs_(GenerateSsrcs(num_video_streams_, 200)),
54 audio_ssrcs_(GenerateSsrcs(num_audio_streams_, 300)),
Peter Boström8c38e8b2015-11-26 17:45:47 +010055 poller_thread_(&BitrateStatsPollingThread,
56 this,
mflodman86cc6ff2016-07-26 04:44:06 -070057 "BitrateStatsPollingThread") {
Stefan Holmerff2a6352016-01-14 10:00:21 +010058 EXPECT_LE(num_audio_streams_, 1u);
stefan4fbd1452015-09-28 03:57:14 -070059 if (rtx_) {
stefanff483612015-12-21 03:14:00 -080060 for (size_t i = 0; i < video_ssrcs_.size(); ++i)
61 rtx_ssrc_map_[video_rtx_ssrcs_[i]] = video_ssrcs_[i];
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000062 }
stefan4fbd1452015-09-28 03:57:14 -070063}
64
65RampUpTester::~RampUpTester() {
66 event_.Set();
stefan4fbd1452015-09-28 03:57:14 -070067}
68
69Call::Config RampUpTester::GetSenderCallConfig() {
70 Call::Config call_config;
71 if (start_bitrate_bps_ != 0) {
72 call_config.bitrate_config.start_bitrate_bps = start_bitrate_bps_;
73 }
74 call_config.bitrate_config.min_bitrate_bps = 10000;
75 return call_config;
76}
77
stefanff483612015-12-21 03:14:00 -080078void RampUpTester::OnVideoStreamsCreated(
stefan4fbd1452015-09-28 03:57:14 -070079 VideoSendStream* send_stream,
80 const std::vector<VideoReceiveStream*>& receive_streams) {
81 send_stream_ = send_stream;
82}
83
stefane74eef12016-01-08 06:47:13 -080084test::PacketTransport* RampUpTester::CreateSendTransport(Call* sender_call) {
85 send_transport_ = new test::PacketTransport(sender_call, this,
86 test::PacketTransport::kSender,
87 forward_transport_config_);
88 return send_transport_;
stefanf116bd02015-10-27 08:29:42 -070089}
90
Stefan Holmerd20e6512016-01-12 15:51:22 +010091size_t RampUpTester::GetNumVideoStreams() const {
92 return num_video_streams_;
93}
94
Stefan Holmerff2a6352016-01-14 10:00:21 +010095size_t RampUpTester::GetNumAudioStreams() const {
96 return num_audio_streams_;
97}
98
stefanff483612015-12-21 03:14:00 -080099void RampUpTester::ModifyVideoConfigs(
stefan4fbd1452015-09-28 03:57:14 -0700100 VideoSendStream::Config* send_config,
101 std::vector<VideoReceiveStream::Config>* receive_configs,
102 VideoEncoderConfig* encoder_config) {
103 send_config->suspend_below_min_bitrate = true;
104
stefanff483612015-12-21 03:14:00 -0800105 if (num_video_streams_ == 1) {
stefan4fbd1452015-09-28 03:57:14 -0700106 encoder_config->streams[0].target_bitrate_bps =
107 encoder_config->streams[0].max_bitrate_bps = 2000000;
108 // For single stream rampup until 1mbps
109 expected_bitrate_bps_ = kSingleStreamTargetBps;
110 } else {
111 // For multi stream rampup until all streams are being sent. That means
112 // enough birate to send all the target streams plus the min bitrate of
113 // the last one.
114 expected_bitrate_bps_ = encoder_config->streams.back().min_bitrate_bps;
115 for (size_t i = 0; i < encoder_config->streams.size() - 1; ++i) {
116 expected_bitrate_bps_ += encoder_config->streams[i].target_bitrate_bps;
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000117 }
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000118 }
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000119
stefan4fbd1452015-09-28 03:57:14 -0700120 send_config->rtp.extensions.clear();
121
122 bool remb;
stefan43edf0f2015-11-20 18:05:48 -0800123 bool transport_cc;
isheriff6f8d6862016-05-26 11:24:55 -0700124 if (extension_type_ == RtpExtension::kAbsSendTimeUri) {
stefan4fbd1452015-09-28 03:57:14 -0700125 remb = true;
stefan43edf0f2015-11-20 18:05:48 -0800126 transport_cc = false;
stefan4fbd1452015-09-28 03:57:14 -0700127 send_config->rtp.extensions.push_back(
128 RtpExtension(extension_type_.c_str(), kAbsSendTimeExtensionId));
isheriff6f8d6862016-05-26 11:24:55 -0700129 } else if (extension_type_ == RtpExtension::kTransportSequenceNumberUri) {
stefan4fbd1452015-09-28 03:57:14 -0700130 remb = false;
stefan43edf0f2015-11-20 18:05:48 -0800131 transport_cc = true;
stefan4fbd1452015-09-28 03:57:14 -0700132 send_config->rtp.extensions.push_back(RtpExtension(
133 extension_type_.c_str(), kTransportSequenceNumberExtensionId));
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000134 } else {
stefan4fbd1452015-09-28 03:57:14 -0700135 remb = true;
stefan43edf0f2015-11-20 18:05:48 -0800136 transport_cc = false;
stefan4fbd1452015-09-28 03:57:14 -0700137 send_config->rtp.extensions.push_back(RtpExtension(
138 extension_type_.c_str(), kTransmissionTimeOffsetExtensionId));
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000139 }
stefan4fbd1452015-09-28 03:57:14 -0700140
141 send_config->rtp.nack.rtp_history_ms = test::CallTest::kNackRtpHistoryMs;
stefanff483612015-12-21 03:14:00 -0800142 send_config->rtp.ssrcs = video_ssrcs_;
stefan4fbd1452015-09-28 03:57:14 -0700143 if (rtx_) {
144 send_config->rtp.rtx.payload_type = test::CallTest::kSendRtxPayloadType;
stefanff483612015-12-21 03:14:00 -0800145 send_config->rtp.rtx.ssrcs = video_rtx_ssrcs_;
stefan4fbd1452015-09-28 03:57:14 -0700146 }
147 if (red_) {
148 send_config->rtp.fec.ulpfec_payload_type =
149 test::CallTest::kUlpfecPayloadType;
150 send_config->rtp.fec.red_payload_type = test::CallTest::kRedPayloadType;
151 }
152
153 size_t i = 0;
154 for (VideoReceiveStream::Config& recv_config : *receive_configs) {
155 recv_config.rtp.remb = remb;
stefan43edf0f2015-11-20 18:05:48 -0800156 recv_config.rtp.transport_cc = transport_cc;
stefan4fbd1452015-09-28 03:57:14 -0700157 recv_config.rtp.extensions = send_config->rtp.extensions;
158
stefanff483612015-12-21 03:14:00 -0800159 recv_config.rtp.remote_ssrc = video_ssrcs_[i];
stefan4fbd1452015-09-28 03:57:14 -0700160 recv_config.rtp.nack.rtp_history_ms = send_config->rtp.nack.rtp_history_ms;
161
162 if (red_) {
163 recv_config.rtp.fec.red_payload_type =
164 send_config->rtp.fec.red_payload_type;
165 recv_config.rtp.fec.ulpfec_payload_type =
166 send_config->rtp.fec.ulpfec_payload_type;
167 }
168
169 if (rtx_) {
170 recv_config.rtp.rtx[send_config->encoder_settings.payload_type].ssrc =
stefanff483612015-12-21 03:14:00 -0800171 video_rtx_ssrcs_[i];
stefan4fbd1452015-09-28 03:57:14 -0700172 recv_config.rtp.rtx[send_config->encoder_settings.payload_type]
173 .payload_type = send_config->rtp.rtx.payload_type;
174 }
175 ++i;
176 }
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000177}
178
Stefan Holmerff2a6352016-01-14 10:00:21 +0100179void RampUpTester::ModifyAudioConfigs(
180 AudioSendStream::Config* send_config,
181 std::vector<AudioReceiveStream::Config>* receive_configs) {
182 if (num_audio_streams_ == 0)
183 return;
184
isheriff6f8d6862016-05-26 11:24:55 -0700185 EXPECT_NE(RtpExtension::kTimestampOffsetUri, extension_type_)
Stefan Holmerff2a6352016-01-14 10:00:21 +0100186 << "Audio BWE not supported with toffset.";
187
188 send_config->rtp.ssrc = audio_ssrcs_[0];
189 send_config->rtp.extensions.clear();
190
mflodman86cc6ff2016-07-26 04:44:06 -0700191 send_config->min_bitrate_kbps = 6;
192 send_config->max_bitrate_kbps = 60;
193
Stefan Holmerff2a6352016-01-14 10:00:21 +0100194 bool transport_cc = false;
isheriff6f8d6862016-05-26 11:24:55 -0700195 if (extension_type_ == RtpExtension::kAbsSendTimeUri) {
Stefan Holmerff2a6352016-01-14 10:00:21 +0100196 transport_cc = false;
197 send_config->rtp.extensions.push_back(
198 RtpExtension(extension_type_.c_str(), kAbsSendTimeExtensionId));
isheriff6f8d6862016-05-26 11:24:55 -0700199 } else if (extension_type_ == RtpExtension::kTransportSequenceNumberUri) {
Stefan Holmerff2a6352016-01-14 10:00:21 +0100200 transport_cc = true;
201 send_config->rtp.extensions.push_back(RtpExtension(
202 extension_type_.c_str(), kTransportSequenceNumberExtensionId));
203 }
204
205 for (AudioReceiveStream::Config& recv_config : *receive_configs) {
Stefan Holmerff2a6352016-01-14 10:00:21 +0100206 recv_config.rtp.transport_cc = transport_cc;
207 recv_config.rtp.extensions = send_config->rtp.extensions;
208 recv_config.rtp.remote_ssrc = send_config->rtp.ssrc;
209 }
210}
211
stefan4fbd1452015-09-28 03:57:14 -0700212void RampUpTester::OnCallsCreated(Call* sender_call, Call* receiver_call) {
213 sender_call_ = sender_call;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000214}
215
stefan4fbd1452015-09-28 03:57:14 -0700216bool RampUpTester::BitrateStatsPollingThread(void* obj) {
217 return static_cast<RampUpTester*>(obj)->PollStats();
pbos@webrtc.org32452b22014-10-22 12:15:24 +0000218}
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000219
stefan4fbd1452015-09-28 03:57:14 -0700220bool RampUpTester::PollStats() {
221 if (sender_call_) {
222 Call::Stats stats = sender_call_->GetStats();
223
224 RTC_DCHECK_GT(expected_bitrate_bps_, 0);
225 if (!start_bitrate_verified_ && start_bitrate_bps_ != 0) {
226 // For tests with an explicitly set start bitrate, verify the first
227 // bitrate estimate is close to the start bitrate and lower than the
228 // test target bitrate. This is to verify a call respects the configured
229 // start bitrate, but due to the BWE implementation we can't guarantee the
230 // first estimate really is as high as the start bitrate.
231 EXPECT_GT(stats.send_bandwidth_bps, 0.9 * start_bitrate_bps_);
232 start_bitrate_verified_ = true;
233 }
234 if (stats.send_bandwidth_bps >= expected_bitrate_bps_) {
235 ramp_up_finished_ms_ = clock_->TimeInMilliseconds();
Peter Boström5811a392015-12-10 13:02:50 +0100236 observation_complete_.Set();
stefan4fbd1452015-09-28 03:57:14 -0700237 }
238 }
239
240 return !event_.Wait(kPollIntervalMs);
Erik Språng468e62a2015-07-06 10:50:47 +0200241}
242
stefan4fbd1452015-09-28 03:57:14 -0700243void RampUpTester::ReportResult(const std::string& measurement,
244 size_t value,
245 const std::string& units) const {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000246 webrtc::test::PrintResult(
247 measurement, "",
stefanff483612015-12-21 03:14:00 -0800248 ::testing::UnitTest::GetInstance()->current_test_info()->name(), value,
249 units, false);
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000250}
251
stefan092508a2015-09-29 02:26:42 -0700252void RampUpTester::AccumulateStats(const VideoSendStream::StreamStats& stream,
253 size_t* total_packets_sent,
254 size_t* total_sent,
255 size_t* padding_sent,
256 size_t* media_sent) const {
stefan4fbd1452015-09-28 03:57:14 -0700257 *total_packets_sent += stream.rtp_stats.transmitted.packets +
258 stream.rtp_stats.retransmitted.packets +
259 stream.rtp_stats.fec.packets;
260 *total_sent += stream.rtp_stats.transmitted.TotalBytes() +
261 stream.rtp_stats.retransmitted.TotalBytes() +
262 stream.rtp_stats.fec.TotalBytes();
263 *padding_sent += stream.rtp_stats.transmitted.padding_bytes +
264 stream.rtp_stats.retransmitted.padding_bytes +
265 stream.rtp_stats.fec.padding_bytes;
266 *media_sent += stream.rtp_stats.MediaPayloadBytes();
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000267}
268
stefan4fbd1452015-09-28 03:57:14 -0700269void RampUpTester::TriggerTestDone() {
Erik Språngf3a7c9d2015-10-05 14:03:22 +0200270 RTC_DCHECK_GE(test_start_ms_, 0);
271
Stefan Holmerff2a6352016-01-14 10:00:21 +0100272 // TODO(holmer): Add audio send stats here too when those APIs are available.
mflodman86cc6ff2016-07-26 04:44:06 -0700273 if (!send_stream_)
274 return;
275
stefan4fbd1452015-09-28 03:57:14 -0700276 VideoSendStream::Stats send_stats = send_stream_->GetStats();
277
278 size_t total_packets_sent = 0;
279 size_t total_sent = 0;
280 size_t padding_sent = 0;
281 size_t media_sent = 0;
stefanff483612015-12-21 03:14:00 -0800282 for (uint32_t ssrc : video_ssrcs_) {
stefan092508a2015-09-29 02:26:42 -0700283 AccumulateStats(send_stats.substreams[ssrc], &total_packets_sent,
284 &total_sent, &padding_sent, &media_sent);
stefan4fbd1452015-09-28 03:57:14 -0700285 }
286
287 size_t rtx_total_packets_sent = 0;
288 size_t rtx_total_sent = 0;
289 size_t rtx_padding_sent = 0;
290 size_t rtx_media_sent = 0;
stefanff483612015-12-21 03:14:00 -0800291 for (uint32_t rtx_ssrc : video_rtx_ssrcs_) {
stefan092508a2015-09-29 02:26:42 -0700292 AccumulateStats(send_stats.substreams[rtx_ssrc], &rtx_total_packets_sent,
293 &rtx_total_sent, &rtx_padding_sent, &rtx_media_sent);
stefan4fbd1452015-09-28 03:57:14 -0700294 }
295
296 ReportResult("ramp-up-total-packets-sent", total_packets_sent, "packets");
297 ReportResult("ramp-up-total-sent", total_sent, "bytes");
298 ReportResult("ramp-up-media-sent", media_sent, "bytes");
299 ReportResult("ramp-up-padding-sent", padding_sent, "bytes");
300 ReportResult("ramp-up-rtx-total-packets-sent", rtx_total_packets_sent,
301 "packets");
302 ReportResult("ramp-up-rtx-total-sent", rtx_total_sent, "bytes");
303 ReportResult("ramp-up-rtx-media-sent", rtx_media_sent, "bytes");
304 ReportResult("ramp-up-rtx-padding-sent", rtx_padding_sent, "bytes");
305 if (ramp_up_finished_ms_ >= 0) {
306 ReportResult("ramp-up-time", ramp_up_finished_ms_ - test_start_ms_,
307 "milliseconds");
308 }
Stefan Holmerff2a6352016-01-14 10:00:21 +0100309 ReportResult("ramp-up-average-network-latency",
310 send_transport_->GetAverageDelayMs(), "milliseconds");
stefan4fbd1452015-09-28 03:57:14 -0700311}
312
313void RampUpTester::PerformTest() {
Erik Språngf3a7c9d2015-10-05 14:03:22 +0200314 test_start_ms_ = clock_->TimeInMilliseconds();
Peter Boström8c38e8b2015-11-26 17:45:47 +0100315 poller_thread_.Start();
Peter Boström5811a392015-12-10 13:02:50 +0100316 EXPECT_TRUE(Wait()) << "Timed out while waiting for ramp-up to complete.";
stefan4fbd1452015-09-28 03:57:14 -0700317 TriggerTestDone();
Peter Boström8c38e8b2015-11-26 17:45:47 +0100318 poller_thread_.Stop();
stefan4fbd1452015-09-28 03:57:14 -0700319}
320
Stefan Holmerff2a6352016-01-14 10:00:21 +0100321RampUpDownUpTester::RampUpDownUpTester(size_t num_video_streams,
322 size_t num_audio_streams,
stefan4fbd1452015-09-28 03:57:14 -0700323 unsigned int start_bitrate_bps,
324 const std::string& extension_type,
325 bool rtx,
326 bool red)
Stefan Holmerff2a6352016-01-14 10:00:21 +0100327 : RampUpTester(num_video_streams,
328 num_audio_streams,
329 start_bitrate_bps,
330 extension_type,
331 rtx,
332 red),
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000333 test_state_(kFirstRampup),
334 state_start_ms_(clock_->TimeInMilliseconds()),
stefan4fbd1452015-09-28 03:57:14 -0700335 interval_start_ms_(clock_->TimeInMilliseconds()),
336 sent_bytes_(0) {
stefanff483612015-12-21 03:14:00 -0800337 forward_transport_config_.link_capacity_kbps = kHighBandwidthLimitBps / 1000;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000338}
339
stefan4fbd1452015-09-28 03:57:14 -0700340RampUpDownUpTester::~RampUpDownUpTester() {}
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000341
stefan4fbd1452015-09-28 03:57:14 -0700342bool RampUpDownUpTester::PollStats() {
343 if (send_stream_) {
344 webrtc::VideoSendStream::Stats stats = send_stream_->GetStats();
345 int transmit_bitrate_bps = 0;
346 for (auto it : stats.substreams) {
347 transmit_bitrate_bps += it.second.total_bitrate_bps;
mflodman@webrtc.orgeb16b812014-06-16 08:57:39 +0000348 }
stefan4fbd1452015-09-28 03:57:14 -0700349 EvolveTestState(transmit_bitrate_bps, stats.suspended);
mflodman86cc6ff2016-07-26 04:44:06 -0700350 } else if (num_audio_streams_ > 0 && sender_call_ != nullptr) {
351 // An audio send stream doesn't have bitrate stats, so the call send BW is
352 // currently used instead.
353 int transmit_bitrate_bps = sender_call_->GetStats().send_bandwidth_bps;
354 EvolveTestState(transmit_bitrate_bps, false);
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000355 }
stefan4fbd1452015-09-28 03:57:14 -0700356
357 return !event_.Wait(kPollIntervalMs);
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000358}
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000359
stefan4fbd1452015-09-28 03:57:14 -0700360Call::Config RampUpDownUpTester::GetReceiverCallConfig() {
361 Call::Config config;
362 config.bitrate_config.min_bitrate_bps = 10000;
363 return config;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000364}
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000365
stefan4fbd1452015-09-28 03:57:14 -0700366std::string RampUpDownUpTester::GetModifierString() const {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000367 std::string str("_");
stefanff483612015-12-21 03:14:00 -0800368 if (num_video_streams_ > 0) {
369 std::ostringstream s;
370 s << num_video_streams_;
371 str += s.str();
372 str += "stream";
373 str += (num_video_streams_ > 1 ? "s" : "");
374 str += "_";
375 }
376 if (num_audio_streams_ > 0) {
377 std::ostringstream s;
378 s << num_audio_streams_;
379 str += s.str();
380 str += "stream";
381 str += (num_audio_streams_ > 1 ? "s" : "");
382 str += "_";
383 }
stefan4fbd1452015-09-28 03:57:14 -0700384 str += (rtx_ ? "" : "no");
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000385 str += "rtx";
386 return str;
387}
andresp@webrtc.orgc1480792014-03-20 03:23:55 +0000388
stefan4fbd1452015-09-28 03:57:14 -0700389void RampUpDownUpTester::EvolveTestState(int bitrate_bps, bool suspended) {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000390 int64_t now = clock_->TimeInMilliseconds();
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000391 switch (test_state_) {
392 case kFirstRampup: {
stefan4fbd1452015-09-28 03:57:14 -0700393 EXPECT_FALSE(suspended);
mflodman86cc6ff2016-07-26 04:44:06 -0700394 if (bitrate_bps >= kExpectedHighBitrateBps) {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000395 // The first ramp-up has reached the target bitrate. Change the
396 // channel limit, and move to the next test state.
397 forward_transport_config_.link_capacity_kbps =
398 kLowBandwidthLimitBps / 1000;
stefanf116bd02015-10-27 08:29:42 -0700399 send_transport_->SetConfig(forward_transport_config_);
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000400 test_state_ = kLowRate;
stefanff483612015-12-21 03:14:00 -0800401 webrtc::test::PrintResult("ramp_up_down_up", GetModifierString(),
402 "first_rampup", now - state_start_ms_, "ms",
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000403 false);
404 state_start_ms_ = now;
405 interval_start_ms_ = now;
406 sent_bytes_ = 0;
andresp@webrtc.orgc1480792014-03-20 03:23:55 +0000407 }
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000408 break;
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +0000409 }
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000410 case kLowRate: {
mflodman86cc6ff2016-07-26 04:44:06 -0700411 // Audio streams are never suspended.
412 bool check_suspend_state = num_video_streams_ > 0;
413 if (bitrate_bps < kExpectedLowBitrateBps &&
414 suspended == check_suspend_state) {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000415 // The ramp-down was successful. Change the channel limit back to a
416 // high value, and move to the next test state.
417 forward_transport_config_.link_capacity_kbps =
418 kHighBandwidthLimitBps / 1000;
stefanf116bd02015-10-27 08:29:42 -0700419 send_transport_->SetConfig(forward_transport_config_);
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000420 test_state_ = kSecondRampup;
stefanff483612015-12-21 03:14:00 -0800421 webrtc::test::PrintResult("ramp_up_down_up", GetModifierString(),
422 "rampdown", now - state_start_ms_, "ms",
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000423 false);
424 state_start_ms_ = now;
425 interval_start_ms_ = now;
426 sent_bytes_ = 0;
427 }
428 break;
429 }
430 case kSecondRampup: {
mflodman86cc6ff2016-07-26 04:44:06 -0700431 if (bitrate_bps >= kExpectedHighBitrateBps && !suspended) {
stefanff483612015-12-21 03:14:00 -0800432 webrtc::test::PrintResult("ramp_up_down_up", GetModifierString(),
433 "second_rampup", now - state_start_ms_, "ms",
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000434 false);
Stefan Holmerff2a6352016-01-14 10:00:21 +0100435 ReportResult("ramp-up-down-up-average-network-latency",
436 send_transport_->GetAverageDelayMs(), "milliseconds");
Peter Boström5811a392015-12-10 13:02:50 +0100437 observation_complete_.Set();
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000438 }
439 break;
440 }
441 }
442}
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +0000443
stefan4fbd1452015-09-28 03:57:14 -0700444class RampUpTest : public test::CallTest {
Erik Språng6b8d3552015-09-24 15:06:57 +0200445 public:
stefan4fbd1452015-09-28 03:57:14 -0700446 RampUpTest() {}
Erik Språng6b8d3552015-09-24 15:06:57 +0200447
stefan4fbd1452015-09-28 03:57:14 -0700448 virtual ~RampUpTest() {
stefanff483612015-12-21 03:14:00 -0800449 EXPECT_EQ(nullptr, video_send_stream_);
450 EXPECT_TRUE(video_receive_streams_.empty());
Erik Språng6b8d3552015-09-24 15:06:57 +0200451 }
Erik Språng6b8d3552015-09-24 15:06:57 +0200452};
453
stefan@webrtc.orgcb254aa2014-06-12 15:12:25 +0000454TEST_F(RampUpTest, SingleStream) {
isheriff6f8d6862016-05-26 11:24:55 -0700455 RampUpTester test(1, 0, 0, RtpExtension::kTimestampOffsetUri, false, false);
stefane74eef12016-01-08 06:47:13 -0800456 RunBaseTest(&test);
andresp@webrtc.orgc1480792014-03-20 03:23:55 +0000457}
pbos@webrtc.org744fbc72013-09-10 09:26:25 +0000458
stefan@webrtc.orgcb254aa2014-06-12 15:12:25 +0000459TEST_F(RampUpTest, Simulcast) {
isheriff6f8d6862016-05-26 11:24:55 -0700460 RampUpTester test(3, 0, 0, RtpExtension::kTimestampOffsetUri, false, false);
stefane74eef12016-01-08 06:47:13 -0800461 RunBaseTest(&test);
andresp@webrtc.orgc1480792014-03-20 03:23:55 +0000462}
463
stefan@webrtc.orgcb254aa2014-06-12 15:12:25 +0000464TEST_F(RampUpTest, SimulcastWithRtx) {
isheriff6f8d6862016-05-26 11:24:55 -0700465 RampUpTester test(3, 0, 0, RtpExtension::kTimestampOffsetUri, true, false);
stefane74eef12016-01-08 06:47:13 -0800466 RunBaseTest(&test);
Shao Changbine62202f2015-04-21 20:24:50 +0800467}
468
469TEST_F(RampUpTest, SimulcastByRedWithRtx) {
isheriff6f8d6862016-05-26 11:24:55 -0700470 RampUpTester test(3, 0, 0, RtpExtension::kTimestampOffsetUri, true, true);
stefane74eef12016-01-08 06:47:13 -0800471 RunBaseTest(&test);
mflodman@webrtc.orgeb16b812014-06-16 08:57:39 +0000472}
473
474TEST_F(RampUpTest, SingleStreamWithHighStartBitrate) {
isheriff6f8d6862016-05-26 11:24:55 -0700475 RampUpTester test(1, 0, 0.9 * kSingleStreamTargetBps,
476 RtpExtension::kTimestampOffsetUri, false, false);
stefane74eef12016-01-08 06:47:13 -0800477 RunBaseTest(&test);
andresp@webrtc.orgc1480792014-03-20 03:23:55 +0000478}
pbos@webrtc.org744fbc72013-09-10 09:26:25 +0000479
Stefan Holmerff2a6352016-01-14 10:00:21 +0100480static const uint32_t kStartBitrateBps = 60000;
481
philipelf4d84412016-02-23 18:56:36 +0100482// Disabled: https://bugs.chromium.org/p/webrtc/issues/detail?id=5576
483TEST_F(RampUpTest, DISABLED_UpDownUpOneStream) {
isheriff6f8d6862016-05-26 11:24:55 -0700484 RampUpDownUpTester test(1, 0, kStartBitrateBps, RtpExtension::kAbsSendTimeUri,
Stefan Holmerff2a6352016-01-14 10:00:21 +0100485 false, false);
stefane74eef12016-01-08 06:47:13 -0800486 RunBaseTest(&test);
Shao Changbine62202f2015-04-21 20:24:50 +0800487}
henrik.lundin@webrtc.org845862f2014-03-06 07:19:28 +0000488
Shao Changbine62202f2015-04-21 20:24:50 +0800489TEST_F(RampUpTest, UpDownUpThreeStreams) {
isheriff6f8d6862016-05-26 11:24:55 -0700490 RampUpDownUpTester test(3, 0, kStartBitrateBps, RtpExtension::kAbsSendTimeUri,
Stefan Holmerff2a6352016-01-14 10:00:21 +0100491 false, false);
stefane74eef12016-01-08 06:47:13 -0800492 RunBaseTest(&test);
Shao Changbine62202f2015-04-21 20:24:50 +0800493}
henrik.lundin@webrtc.org998cb8f2014-03-06 09:12:00 +0000494
philipelf4d84412016-02-23 18:56:36 +0100495// Disabled: https://bugs.chromium.org/p/webrtc/issues/detail?id=5576
496TEST_F(RampUpTest, DISABLED_UpDownUpOneStreamRtx) {
isheriff6f8d6862016-05-26 11:24:55 -0700497 RampUpDownUpTester test(1, 0, kStartBitrateBps, RtpExtension::kAbsSendTimeUri,
Stefan Holmerff2a6352016-01-14 10:00:21 +0100498 true, false);
stefane74eef12016-01-08 06:47:13 -0800499 RunBaseTest(&test);
Shao Changbine62202f2015-04-21 20:24:50 +0800500}
henrik.lundin@webrtc.org998cb8f2014-03-06 09:12:00 +0000501
Shao Changbine62202f2015-04-21 20:24:50 +0800502TEST_F(RampUpTest, UpDownUpThreeStreamsRtx) {
isheriff6f8d6862016-05-26 11:24:55 -0700503 RampUpDownUpTester test(3, 0, kStartBitrateBps, RtpExtension::kAbsSendTimeUri,
Stefan Holmerff2a6352016-01-14 10:00:21 +0100504 true, false);
stefane74eef12016-01-08 06:47:13 -0800505 RunBaseTest(&test);
Shao Changbine62202f2015-04-21 20:24:50 +0800506}
507
philipelf4d84412016-02-23 18:56:36 +0100508// Disabled: https://bugs.chromium.org/p/webrtc/issues/detail?id=5576
509TEST_F(RampUpTest, DISABLED_UpDownUpOneStreamByRedRtx) {
isheriff6f8d6862016-05-26 11:24:55 -0700510 RampUpDownUpTester test(1, 0, kStartBitrateBps, RtpExtension::kAbsSendTimeUri,
Stefan Holmerff2a6352016-01-14 10:00:21 +0100511 true, true);
stefane74eef12016-01-08 06:47:13 -0800512 RunBaseTest(&test);
Shao Changbine62202f2015-04-21 20:24:50 +0800513}
514
515TEST_F(RampUpTest, UpDownUpThreeStreamsByRedRtx) {
isheriff6f8d6862016-05-26 11:24:55 -0700516 RampUpDownUpTester test(3, 0, kStartBitrateBps, RtpExtension::kAbsSendTimeUri,
Stefan Holmerff2a6352016-01-14 10:00:21 +0100517 true, true);
stefane74eef12016-01-08 06:47:13 -0800518 RunBaseTest(&test);
Shao Changbine62202f2015-04-21 20:24:50 +0800519}
Stefan Holmerff2a6352016-01-14 10:00:21 +0100520
521TEST_F(RampUpTest, SendSideVideoUpDownUpRtx) {
522 RampUpDownUpTester test(3, 0, kStartBitrateBps,
isheriff6f8d6862016-05-26 11:24:55 -0700523 RtpExtension::kTransportSequenceNumberUri, true,
524 false);
Stefan Holmerff2a6352016-01-14 10:00:21 +0100525 RunBaseTest(&test);
526}
527
528// TODO(holmer): Enable when audio bitrates are included in the bitrate
529// allocation.
530TEST_F(RampUpTest, DISABLED_SendSideAudioVideoUpDownUpRtx) {
531 RampUpDownUpTester test(3, 1, kStartBitrateBps,
isheriff6f8d6862016-05-26 11:24:55 -0700532 RtpExtension::kTransportSequenceNumberUri, true,
533 false);
Stefan Holmerff2a6352016-01-14 10:00:21 +0100534 RunBaseTest(&test);
535}
536
mflodman86cc6ff2016-07-26 04:44:06 -0700537TEST_F(RampUpTest, SendSideAudioOnlyUpDownUpRtx) {
538 RampUpDownUpTester test(0, 1, kStartBitrateBps,
539 RtpExtension::kTransportSequenceNumberUri, true,
540 false);
541 RunBaseTest(&test);
542}
543
pbos@webrtc.org85bd53e2014-12-10 10:36:20 +0000544TEST_F(RampUpTest, AbsSendTimeSingleStream) {
isheriff6f8d6862016-05-26 11:24:55 -0700545 RampUpTester test(1, 0, 0, RtpExtension::kAbsSendTimeUri, false, false);
stefane74eef12016-01-08 06:47:13 -0800546 RunBaseTest(&test);
pbos@webrtc.org85bd53e2014-12-10 10:36:20 +0000547}
548
549TEST_F(RampUpTest, AbsSendTimeSimulcast) {
isheriff6f8d6862016-05-26 11:24:55 -0700550 RampUpTester test(3, 0, 0, RtpExtension::kAbsSendTimeUri, false, false);
stefane74eef12016-01-08 06:47:13 -0800551 RunBaseTest(&test);
pbos@webrtc.org85bd53e2014-12-10 10:36:20 +0000552}
553
554TEST_F(RampUpTest, AbsSendTimeSimulcastWithRtx) {
isheriff6f8d6862016-05-26 11:24:55 -0700555 RampUpTester test(3, 0, 0, RtpExtension::kAbsSendTimeUri, true, false);
stefane74eef12016-01-08 06:47:13 -0800556 RunBaseTest(&test);
Shao Changbine62202f2015-04-21 20:24:50 +0800557}
558
559TEST_F(RampUpTest, AbsSendTimeSimulcastByRedWithRtx) {
isheriff6f8d6862016-05-26 11:24:55 -0700560 RampUpTester test(3, 0, 0, RtpExtension::kAbsSendTimeUri, true, true);
stefane74eef12016-01-08 06:47:13 -0800561 RunBaseTest(&test);
pbos@webrtc.org85bd53e2014-12-10 10:36:20 +0000562}
563
564TEST_F(RampUpTest, AbsSendTimeSingleStreamWithHighStartBitrate) {
stefanff483612015-12-21 03:14:00 -0800565 RampUpTester test(1, 0, 0.9 * kSingleStreamTargetBps,
isheriff6f8d6862016-05-26 11:24:55 -0700566 RtpExtension::kAbsSendTimeUri, false, false);
stefane74eef12016-01-08 06:47:13 -0800567 RunBaseTest(&test);
pbos@webrtc.org85bd53e2014-12-10 10:36:20 +0000568}
Erik Språng6b8d3552015-09-24 15:06:57 +0200569
570TEST_F(RampUpTest, TransportSequenceNumberSingleStream) {
isheriff6f8d6862016-05-26 11:24:55 -0700571 RampUpTester test(1, 0, 0, RtpExtension::kTransportSequenceNumberUri, false,
stefanff483612015-12-21 03:14:00 -0800572 false);
stefane74eef12016-01-08 06:47:13 -0800573 RunBaseTest(&test);
Erik Språng6b8d3552015-09-24 15:06:57 +0200574}
575
576TEST_F(RampUpTest, TransportSequenceNumberSimulcast) {
isheriff6f8d6862016-05-26 11:24:55 -0700577 RampUpTester test(3, 0, 0, RtpExtension::kTransportSequenceNumberUri, false,
stefanff483612015-12-21 03:14:00 -0800578 false);
stefane74eef12016-01-08 06:47:13 -0800579 RunBaseTest(&test);
Erik Språng6b8d3552015-09-24 15:06:57 +0200580}
581
582TEST_F(RampUpTest, TransportSequenceNumberSimulcastWithRtx) {
isheriff6f8d6862016-05-26 11:24:55 -0700583 RampUpTester test(3, 0, 0, RtpExtension::kTransportSequenceNumberUri, true,
stefanff483612015-12-21 03:14:00 -0800584 false);
stefane74eef12016-01-08 06:47:13 -0800585 RunBaseTest(&test);
Erik Språng6b8d3552015-09-24 15:06:57 +0200586}
587
Stefan Holmerff2a6352016-01-14 10:00:21 +0100588TEST_F(RampUpTest, AudioVideoTransportSequenceNumberSimulcastWithRtx) {
isheriff6f8d6862016-05-26 11:24:55 -0700589 RampUpTester test(3, 1, 0, RtpExtension::kTransportSequenceNumberUri, true,
Stefan Holmerff2a6352016-01-14 10:00:21 +0100590 false);
591 RunBaseTest(&test);
592}
593
Erik Språng6b8d3552015-09-24 15:06:57 +0200594TEST_F(RampUpTest, TransportSequenceNumberSimulcastByRedWithRtx) {
isheriff6f8d6862016-05-26 11:24:55 -0700595 RampUpTester test(3, 0, 0, RtpExtension::kTransportSequenceNumberUri, true,
stefanff483612015-12-21 03:14:00 -0800596 true);
stefane74eef12016-01-08 06:47:13 -0800597 RunBaseTest(&test);
Erik Språng6b8d3552015-09-24 15:06:57 +0200598}
599
600TEST_F(RampUpTest, TransportSequenceNumberSingleStreamWithHighStartBitrate) {
stefanff483612015-12-21 03:14:00 -0800601 RampUpTester test(1, 0, 0.9 * kSingleStreamTargetBps,
isheriff6f8d6862016-05-26 11:24:55 -0700602 RtpExtension::kTransportSequenceNumberUri, false, false);
stefane74eef12016-01-08 06:47:13 -0800603 RunBaseTest(&test);
Erik Språng6b8d3552015-09-24 15:06:57 +0200604}
pbos@webrtc.org744fbc72013-09-10 09:26:25 +0000605} // namespace webrtc