blob: 4ba4cbabe7d3e552a50503ceb35fe7cf11a61852 [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
11#include "testing/gtest/include/gtest/gtest.h"
pbos@webrtc.org2b4ce3a2015-03-23 13:12:24 +000012#include "webrtc/base/checks.h"
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000013#include "webrtc/base/common.h"
pbos@webrtc.org744fbc72013-09-10 09:26:25 +000014#include "webrtc/modules/rtp_rtcp/interface/receive_statistics.h"
15#include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h"
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +000016#include "webrtc/modules/rtp_rtcp/interface/rtp_payload_registry.h"
pbos@webrtc.org744fbc72013-09-10 09:26:25 +000017#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h"
18#include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
19#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +000020#include "webrtc/test/testsupport/perf_test.h"
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000021#include "webrtc/video/rampup_tests.h"
pbos@webrtc.org744fbc72013-09-10 09:26:25 +000022
23namespace webrtc {
pbos@webrtc.org29023282013-09-11 10:14:56 +000024namespace {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000025
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +000026static const int kMaxPacketSize = 1500;
pbos@webrtc.org29023282013-09-11 10:14:56 +000027
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000028std::vector<uint32_t> GenerateSsrcs(size_t num_streams,
29 uint32_t ssrc_offset) {
30 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
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000037StreamObserver::StreamObserver(const SsrcMap& rtx_media_ssrcs,
38 newapi::Transport* feedback_transport,
39 Clock* clock,
40 RemoteBitrateEstimatorFactory* rbe_factory,
41 RateControlType control_type)
42 : clock_(clock),
43 test_done_(EventWrapper::Create()),
44 rtp_parser_(RtpHeaderParser::Create()),
45 feedback_transport_(feedback_transport),
46 receive_stats_(ReceiveStatistics::Create(clock)),
47 payload_registry_(
48 new RTPPayloadRegistry(RTPPayloadStrategy::CreateStrategy(false))),
49 crit_(CriticalSectionWrapper::CreateCriticalSection()),
50 expected_bitrate_bps_(0),
51 start_bitrate_bps_(0),
52 rtx_media_ssrcs_(rtx_media_ssrcs),
53 total_sent_(0),
54 padding_sent_(0),
55 rtx_media_sent_(0),
56 total_packets_sent_(0),
57 padding_packets_sent_(0),
58 rtx_media_packets_sent_(0),
59 test_start_ms_(clock_->TimeInMilliseconds()),
60 ramp_up_finished_ms_(0) {
61 // Ideally we would only have to instantiate an RtcpSender, an
62 // RtpHeaderParser and a RemoteBitrateEstimator here, but due to the current
63 // state of the RTP module we need a full module and receive statistics to
64 // be able to produce an RTCP with REMB.
65 RtpRtcp::Configuration config;
66 config.receive_statistics = receive_stats_.get();
67 feedback_transport_.Enable();
68 config.outgoing_transport = &feedback_transport_;
69 rtp_rtcp_.reset(RtpRtcp::CreateRtpRtcp(config));
70 rtp_rtcp_->SetREMBStatus(true);
71 rtp_rtcp_->SetRTCPStatus(kRtcpNonCompound);
72 rtp_parser_->RegisterRtpHeaderExtension(kRtpExtensionAbsoluteSendTime,
73 kAbsSendTimeExtensionId);
74 rtp_parser_->RegisterRtpHeaderExtension(kRtpExtensionTransmissionTimeOffset,
75 kTransmissionTimeOffsetExtensionId);
76 const uint32_t kRemoteBitrateEstimatorMinBitrateBps = 30000;
77 remote_bitrate_estimator_.reset(
78 rbe_factory->Create(this, clock, control_type,
79 kRemoteBitrateEstimatorMinBitrateBps));
Shao Changbine62202f2015-04-21 20:24:50 +080080 payload_registry_->SetRtxPayloadType(RampUpTest::kSendRtxPayloadType,
81 RampUpTest::kFakeSendPayloadType);
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000082}
83
84void StreamObserver::set_expected_bitrate_bps(
85 unsigned int expected_bitrate_bps) {
86 CriticalSectionScoped lock(crit_.get());
87 expected_bitrate_bps_ = expected_bitrate_bps;
88}
89
90void StreamObserver::set_start_bitrate_bps(unsigned int start_bitrate_bps) {
91 CriticalSectionScoped lock(crit_.get());
92 start_bitrate_bps_ = start_bitrate_bps;
93}
94
95void StreamObserver::OnReceiveBitrateChanged(
96 const std::vector<unsigned int>& ssrcs, unsigned int bitrate) {
97 CriticalSectionScoped lock(crit_.get());
pbos@webrtc.org2b4ce3a2015-03-23 13:12:24 +000098 DCHECK_GT(expected_bitrate_bps_, 0u);
stefan@webrtc.org3d7da882014-07-08 13:59:46 +000099 if (start_bitrate_bps_ != 0) {
100 // For tests with an explicitly set start bitrate, verify the first
101 // bitrate estimate is close to the start bitrate and lower than the
102 // test target bitrate. This is to verify a call respects the configured
103 // start bitrate, but due to the BWE implementation we can't guarantee the
104 // first estimate really is as high as the start bitrate.
105 EXPECT_GT(bitrate, 0.9 * start_bitrate_bps_);
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000106 start_bitrate_bps_ = 0;
107 }
108 if (bitrate >= expected_bitrate_bps_) {
109 ramp_up_finished_ms_ = clock_->TimeInMilliseconds();
110 // Just trigger if there was any rtx padding packet.
111 if (rtx_media_ssrcs_.empty() || rtx_media_sent_ > 0) {
112 TriggerTestDone();
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000113 }
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000114 }
pbos@webrtc.org49ff40e2014-11-13 14:42:37 +0000115 rtp_rtcp_->SetREMBData(bitrate, ssrcs);
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000116 rtp_rtcp_->Process();
117}
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000118
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000119bool StreamObserver::SendRtp(const uint8_t* packet, size_t length) {
120 CriticalSectionScoped lock(crit_.get());
121 RTPHeader header;
pbos@webrtc.orgb951eb12014-11-25 11:13:28 +0000122 EXPECT_TRUE(rtp_parser_->Parse(packet, length, &header));
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000123 receive_stats_->IncomingPacket(header, length, false);
andrew@webrtc.org8f27fcc2015-01-09 20:22:46 +0000124 payload_registry_->SetIncomingPayloadType(header);
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000125 remote_bitrate_estimator_->IncomingPacket(
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000126 clock_->TimeInMilliseconds(), length - 12, header);
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000127 if (remote_bitrate_estimator_->TimeUntilNextProcess() <= 0) {
128 remote_bitrate_estimator_->Process();
129 }
130 total_sent_ += length;
131 padding_sent_ += header.paddingLength;
132 ++total_packets_sent_;
133 if (header.paddingLength > 0)
134 ++padding_packets_sent_;
135 if (rtx_media_ssrcs_.find(header.ssrc) != rtx_media_ssrcs_.end()) {
136 rtx_media_sent_ += length - header.headerLength - header.paddingLength;
137 if (header.paddingLength == 0)
138 ++rtx_media_packets_sent_;
139 uint8_t restored_packet[kMaxPacketSize];
140 uint8_t* restored_packet_ptr = restored_packet;
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000141 size_t restored_length = length;
Shao Changbine62202f2015-04-21 20:24:50 +0800142 EXPECT_TRUE(payload_registry_->RestoreOriginalPacket(
143 &restored_packet_ptr, packet, &restored_length,
144 rtx_media_ssrcs_[header.ssrc], header));
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000145 length = restored_length;
146 EXPECT_TRUE(rtp_parser_->Parse(
147 restored_packet, static_cast<int>(length), &header));
148 } else {
149 rtp_rtcp_->SetRemoteSSRC(header.ssrc);
150 }
151 return true;
152}
153
154bool StreamObserver::SendRtcp(const uint8_t* packet, size_t length) {
155 return true;
156}
157
pbos@webrtc.org32452b22014-10-22 12:15:24 +0000158EventTypeWrapper StreamObserver::Wait() {
159 return test_done_->Wait(test::CallTest::kLongTimeoutMs);
160}
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000161
162void StreamObserver::ReportResult(const std::string& measurement,
163 size_t value,
164 const std::string& units) {
165 webrtc::test::PrintResult(
166 measurement, "",
167 ::testing::UnitTest::GetInstance()->current_test_info()->name(),
168 value, units, false);
169}
170
171void StreamObserver::TriggerTestDone() EXCLUSIVE_LOCKS_REQUIRED(crit_) {
172 ReportResult("ramp-up-total-sent", total_sent_, "bytes");
173 ReportResult("ramp-up-padding-sent", padding_sent_, "bytes");
174 ReportResult("ramp-up-rtx-media-sent", rtx_media_sent_, "bytes");
175 ReportResult("ramp-up-total-packets-sent", total_packets_sent_, "packets");
176 ReportResult("ramp-up-padding-packets-sent",
177 padding_packets_sent_,
178 "packets");
179 ReportResult("ramp-up-rtx-packets-sent",
180 rtx_media_packets_sent_,
181 "packets");
182 ReportResult("ramp-up-time",
183 ramp_up_finished_ms_ - test_start_ms_,
184 "milliseconds");
185 test_done_->Set();
186}
187
188LowRateStreamObserver::LowRateStreamObserver(
189 newapi::Transport* feedback_transport,
190 Clock* clock,
191 size_t number_of_streams,
192 bool rtx_used)
193 : clock_(clock),
194 number_of_streams_(number_of_streams),
195 rtx_used_(rtx_used),
196 test_done_(EventWrapper::Create()),
197 rtp_parser_(RtpHeaderParser::Create()),
198 feedback_transport_(feedback_transport),
199 receive_stats_(ReceiveStatistics::Create(clock)),
200 crit_(CriticalSectionWrapper::CreateCriticalSection()),
pbos@webrtc.org2b4ce3a2015-03-23 13:12:24 +0000201 send_stream_(nullptr),
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000202 test_state_(kFirstRampup),
203 state_start_ms_(clock_->TimeInMilliseconds()),
204 interval_start_ms_(state_start_ms_),
205 last_remb_bps_(0),
206 sent_bytes_(0),
207 total_overuse_bytes_(0),
208 suspended_in_stats_(false) {
209 RtpRtcp::Configuration config;
210 config.receive_statistics = receive_stats_.get();
211 feedback_transport_.Enable();
212 config.outgoing_transport = &feedback_transport_;
213 rtp_rtcp_.reset(RtpRtcp::CreateRtpRtcp(config));
214 rtp_rtcp_->SetREMBStatus(true);
215 rtp_rtcp_->SetRTCPStatus(kRtcpNonCompound);
stefan@webrtc.org88172562014-12-19 18:00:21 +0000216 rtp_parser_->RegisterRtpHeaderExtension(kRtpExtensionAbsoluteSendTime,
217 kAbsSendTimeExtensionId);
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000218 AbsoluteSendTimeRemoteBitrateEstimatorFactory rbe_factory;
219 const uint32_t kRemoteBitrateEstimatorMinBitrateBps = 10000;
220 remote_bitrate_estimator_.reset(
stefan@webrtc.org88172562014-12-19 18:00:21 +0000221 rbe_factory.Create(this, clock, kAimdControl,
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000222 kRemoteBitrateEstimatorMinBitrateBps));
223 forward_transport_config_.link_capacity_kbps =
224 kHighBandwidthLimitBps / 1000;
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +0000225 forward_transport_config_.queue_length_packets = 100; // Something large.
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000226 test::DirectTransport::SetConfig(forward_transport_config_);
227 test::DirectTransport::SetReceiver(this);
228}
229
pbos@webrtc.org273a4142014-12-01 15:23:21 +0000230void LowRateStreamObserver::SetSendStream(VideoSendStream* send_stream) {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000231 CriticalSectionScoped lock(crit_.get());
232 send_stream_ = send_stream;
233}
234
235void LowRateStreamObserver::OnReceiveBitrateChanged(
236 const std::vector<unsigned int>& ssrcs,
237 unsigned int bitrate) {
238 CriticalSectionScoped lock(crit_.get());
pbos@webrtc.org49ff40e2014-11-13 14:42:37 +0000239 rtp_rtcp_->SetREMBData(bitrate, ssrcs);
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000240 rtp_rtcp_->Process();
241 last_remb_bps_ = bitrate;
242}
243
244bool LowRateStreamObserver::SendRtp(const uint8_t* data, size_t length) {
245 CriticalSectionScoped lock(crit_.get());
246 sent_bytes_ += length;
247 int64_t now_ms = clock_->TimeInMilliseconds();
248 if (now_ms > interval_start_ms_ + 1000) { // Let at least 1 second pass.
249 // Verify that the send rate was about right.
250 unsigned int average_rate_bps = static_cast<unsigned int>(sent_bytes_) *
251 8 * 1000 / (now_ms - interval_start_ms_);
252 // TODO(holmer): Why is this failing?
253 // EXPECT_LT(average_rate_bps, last_remb_bps_ * 1.1);
254 if (average_rate_bps > last_remb_bps_ * 1.1) {
255 total_overuse_bytes_ +=
256 sent_bytes_ -
257 last_remb_bps_ / 8 * (now_ms - interval_start_ms_) / 1000;
mflodman@webrtc.orgeb16b812014-06-16 08:57:39 +0000258 }
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000259 EvolveTestState(average_rate_bps);
260 interval_start_ms_ = now_ms;
261 sent_bytes_ = 0;
262 }
263 return test::DirectTransport::SendRtp(data, length);
264}
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000265
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000266PacketReceiver::DeliveryStatus LowRateStreamObserver::DeliverPacket(
267 const uint8_t* packet, size_t length) {
268 CriticalSectionScoped lock(crit_.get());
269 RTPHeader header;
pbos@webrtc.orgb951eb12014-11-25 11:13:28 +0000270 EXPECT_TRUE(rtp_parser_->Parse(packet, length, &header));
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000271 receive_stats_->IncomingPacket(header, length, false);
272 remote_bitrate_estimator_->IncomingPacket(
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000273 clock_->TimeInMilliseconds(), length - 12, header);
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000274 if (remote_bitrate_estimator_->TimeUntilNextProcess() <= 0) {
275 remote_bitrate_estimator_->Process();
276 }
277 suspended_in_stats_ = send_stream_->GetStats().suspended;
278 return DELIVERY_OK;
279}
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000280
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000281bool LowRateStreamObserver::SendRtcp(const uint8_t* packet, size_t length) {
282 return true;
283}
andresp@webrtc.orgc1480792014-03-20 03:23:55 +0000284
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000285std::string LowRateStreamObserver::GetModifierString() {
286 std::string str("_");
287 char temp_str[5];
288 sprintf(temp_str, "%i",
289 static_cast<int>(number_of_streams_));
290 str += std::string(temp_str);
291 str += "stream";
292 str += (number_of_streams_ > 1 ? "s" : "");
293 str += "_";
294 str += (rtx_used_ ? "" : "no");
295 str += "rtx";
296 return str;
297}
andresp@webrtc.orgc1480792014-03-20 03:23:55 +0000298
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000299void LowRateStreamObserver::EvolveTestState(unsigned int bitrate_bps) {
300 int64_t now = clock_->TimeInMilliseconds();
301 CriticalSectionScoped lock(crit_.get());
pbos@webrtc.org2b4ce3a2015-03-23 13:12:24 +0000302 DCHECK(send_stream_ != nullptr);
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000303 switch (test_state_) {
304 case kFirstRampup: {
305 EXPECT_FALSE(suspended_in_stats_);
306 if (bitrate_bps > kExpectedHighBitrateBps) {
307 // The first ramp-up has reached the target bitrate. Change the
308 // channel limit, and move to the next test state.
309 forward_transport_config_.link_capacity_kbps =
310 kLowBandwidthLimitBps / 1000;
311 test::DirectTransport::SetConfig(forward_transport_config_);
312 test_state_ = kLowRate;
313 webrtc::test::PrintResult("ramp_up_down_up",
314 GetModifierString(),
315 "first_rampup",
316 now - state_start_ms_,
317 "ms",
318 false);
319 state_start_ms_ = now;
320 interval_start_ms_ = now;
321 sent_bytes_ = 0;
andresp@webrtc.orgc1480792014-03-20 03:23:55 +0000322 }
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000323 break;
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +0000324 }
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000325 case kLowRate: {
326 if (bitrate_bps < kExpectedLowBitrateBps && suspended_in_stats_) {
327 // The ramp-down was successful. Change the channel limit back to a
328 // high value, and move to the next test state.
329 forward_transport_config_.link_capacity_kbps =
330 kHighBandwidthLimitBps / 1000;
331 test::DirectTransport::SetConfig(forward_transport_config_);
332 test_state_ = kSecondRampup;
333 webrtc::test::PrintResult("ramp_up_down_up",
334 GetModifierString(),
335 "rampdown",
336 now - state_start_ms_,
337 "ms",
338 false);
339 state_start_ms_ = now;
340 interval_start_ms_ = now;
341 sent_bytes_ = 0;
342 }
343 break;
344 }
345 case kSecondRampup: {
346 if (bitrate_bps > kExpectedHighBitrateBps && !suspended_in_stats_) {
347 webrtc::test::PrintResult("ramp_up_down_up",
348 GetModifierString(),
349 "second_rampup",
350 now - state_start_ms_,
351 "ms",
352 false);
353 webrtc::test::PrintResult("ramp_up_down_up",
354 GetModifierString(),
355 "total_overuse",
356 total_overuse_bytes_,
357 "bytes",
358 false);
359 test_done_->Set();
360 }
361 break;
362 }
363 }
364}
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +0000365
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000366EventTypeWrapper LowRateStreamObserver::Wait() {
367 return test_done_->Wait(test::CallTest::kLongTimeoutMs);
368}
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000369
Shao Changbine62202f2015-04-21 20:24:50 +0800370void RampUpTest::RunRampUpTest(size_t num_streams,
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000371 unsigned int start_bitrate_bps,
Shao Changbine62202f2015-04-21 20:24:50 +0800372 const std::string& extension_type,
373 bool rtx,
374 bool red) {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000375 std::vector<uint32_t> ssrcs(GenerateSsrcs(num_streams, 100));
376 std::vector<uint32_t> rtx_ssrcs(GenerateSsrcs(num_streams, 200));
377 StreamObserver::SsrcMap rtx_ssrc_map;
378 if (rtx) {
379 for (size_t i = 0; i < ssrcs.size(); ++i)
380 rtx_ssrc_map[rtx_ssrcs[i]] = ssrcs[i];
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000381 }
henrik.lundin@webrtc.org845862f2014-03-06 07:19:28 +0000382
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000383 CreateSendConfig(num_streams);
Erik Språng95261872015-04-10 11:58:49 +0200384 send_config_.rtp.extensions.clear();
henrik.lundin@webrtc.org845862f2014-03-06 07:19:28 +0000385
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000386 rtc::scoped_ptr<RemoteBitrateEstimatorFactory> rbe_factory;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000387 RateControlType control_type;
388 if (extension_type == RtpExtension::kAbsSendTime) {
389 control_type = kAimdControl;
390 rbe_factory.reset(new AbsoluteSendTimeRemoteBitrateEstimatorFactory);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000391 send_config_.rtp.extensions.push_back(RtpExtension(
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000392 extension_type.c_str(), kAbsSendTimeExtensionId));
393 } else {
394 control_type = kMimdControl;
395 rbe_factory.reset(new RemoteBitrateEstimatorFactory);
396 send_config_.rtp.extensions.push_back(RtpExtension(
397 extension_type.c_str(), kTransmissionTimeOffsetExtensionId));
henrik.lundin@webrtc.org845862f2014-03-06 07:19:28 +0000398 }
399
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000400 test::DirectTransport receiver_transport;
401 StreamObserver stream_observer(rtx_ssrc_map,
402 &receiver_transport,
403 Clock::GetRealTimeClock(),
404 rbe_factory.get(),
405 control_type);
406
407 Call::Config call_config(&stream_observer);
408 if (start_bitrate_bps != 0) {
Stefan Holmere5904162015-03-26 11:11:06 +0100409 call_config.bitrate_config.start_bitrate_bps = start_bitrate_bps;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000410 stream_observer.set_start_bitrate_bps(start_bitrate_bps);
andresp@webrtc.orga714eaf2014-03-17 15:34:57 +0000411 }
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000412
413 CreateSenderCall(call_config);
414
415 receiver_transport.SetReceiver(sender_call_->Receiver());
416
417 if (num_streams == 1) {
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +0000418 encoder_config_.streams[0].target_bitrate_bps = 2000000;
419 encoder_config_.streams[0].max_bitrate_bps = 2000000;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000420 }
421
422 send_config_.rtp.nack.rtp_history_ms = kNackRtpHistoryMs;
423 send_config_.rtp.ssrcs = ssrcs;
424 if (rtx) {
425 send_config_.rtp.rtx.payload_type = kSendRtxPayloadType;
426 send_config_.rtp.rtx.ssrcs = rtx_ssrcs;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000427 }
Shao Changbine62202f2015-04-21 20:24:50 +0800428 if (red) {
429 send_config_.rtp.fec.ulpfec_payload_type = kUlpfecPayloadType;
430 send_config_.rtp.fec.red_payload_type = kRedPayloadType;
431 }
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000432
433 if (num_streams == 1) {
434 // For single stream rampup until 1mbps
435 stream_observer.set_expected_bitrate_bps(kSingleStreamTargetBps);
436 } else {
437 // For multi stream rampup until all streams are being sent. That means
438 // enough birate to send all the target streams plus the min bitrate of
439 // the last one.
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +0000440 int expected_bitrate_bps = encoder_config_.streams.back().min_bitrate_bps;
441 for (size_t i = 0; i < encoder_config_.streams.size() - 1; ++i) {
442 expected_bitrate_bps += encoder_config_.streams[i].target_bitrate_bps;
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000443 }
444 stream_observer.set_expected_bitrate_bps(expected_bitrate_bps);
445 }
446
447 CreateStreams();
448 CreateFrameGeneratorCapturer();
449
450 Start();
451
452 EXPECT_EQ(kEventSignaled, stream_observer.Wait());
453
454 Stop();
455 DestroyStreams();
456}
457
Shao Changbine62202f2015-04-21 20:24:50 +0800458void RampUpTest::RunRampUpDownUpTest(size_t number_of_streams,
459 bool rtx,
460 bool red) {
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000461 test::DirectTransport receiver_transport;
462 LowRateStreamObserver stream_observer(
463 &receiver_transport, Clock::GetRealTimeClock(), number_of_streams, rtx);
464
465 Call::Config call_config(&stream_observer);
466 CreateSenderCall(call_config);
467 receiver_transport.SetReceiver(sender_call_->Receiver());
468
469 CreateSendConfig(number_of_streams);
470
471 send_config_.rtp.nack.rtp_history_ms = kNackRtpHistoryMs;
472 send_config_.rtp.extensions.push_back(RtpExtension(
stefan@webrtc.org88172562014-12-19 18:00:21 +0000473 RtpExtension::kAbsSendTime, kAbsSendTimeExtensionId));
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000474 send_config_.suspend_below_min_bitrate = true;
475 if (rtx) {
476 send_config_.rtp.rtx.payload_type = kSendRtxPayloadType;
477 send_config_.rtp.rtx.ssrcs = GenerateSsrcs(number_of_streams, 200);
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000478 }
Shao Changbine62202f2015-04-21 20:24:50 +0800479 if (red) {
480 send_config_.rtp.fec.ulpfec_payload_type = kUlpfecPayloadType;
481 send_config_.rtp.fec.red_payload_type = kRedPayloadType;
482 }
stefan@webrtc.org3d7da882014-07-08 13:59:46 +0000483
484 CreateStreams();
485 stream_observer.SetSendStream(send_stream_);
486
487 CreateFrameGeneratorCapturer();
488
489 Start();
490
491 EXPECT_EQ(kEventSignaled, stream_observer.Wait());
492
493 Stop();
494 DestroyStreams();
495}
pbos@webrtc.org744fbc72013-09-10 09:26:25 +0000496
stefan@webrtc.orgcb254aa2014-06-12 15:12:25 +0000497TEST_F(RampUpTest, SingleStream) {
Shao Changbine62202f2015-04-21 20:24:50 +0800498 RunRampUpTest(1, 0, RtpExtension::kTOffset, false, false);
andresp@webrtc.orgc1480792014-03-20 03:23:55 +0000499}
pbos@webrtc.org744fbc72013-09-10 09:26:25 +0000500
stefan@webrtc.orgcb254aa2014-06-12 15:12:25 +0000501TEST_F(RampUpTest, Simulcast) {
Shao Changbine62202f2015-04-21 20:24:50 +0800502 RunRampUpTest(3, 0, RtpExtension::kTOffset, false, false);
andresp@webrtc.orgc1480792014-03-20 03:23:55 +0000503}
504
stefan@webrtc.orgcb254aa2014-06-12 15:12:25 +0000505TEST_F(RampUpTest, SimulcastWithRtx) {
Shao Changbine62202f2015-04-21 20:24:50 +0800506 RunRampUpTest(3, 0, RtpExtension::kTOffset, true, false);
507}
508
509TEST_F(RampUpTest, SimulcastByRedWithRtx) {
510 RunRampUpTest(3, 0, RtpExtension::kTOffset, true, true);
mflodman@webrtc.orgeb16b812014-06-16 08:57:39 +0000511}
512
513TEST_F(RampUpTest, SingleStreamWithHighStartBitrate) {
Shao Changbine62202f2015-04-21 20:24:50 +0800514 RunRampUpTest(1, 0.9 * kSingleStreamTargetBps, RtpExtension::kTOffset, false,
515 false);
andresp@webrtc.orgc1480792014-03-20 03:23:55 +0000516}
pbos@webrtc.org744fbc72013-09-10 09:26:25 +0000517
Shao Changbine62202f2015-04-21 20:24:50 +0800518TEST_F(RampUpTest, UpDownUpOneStream) {
519 RunRampUpDownUpTest(1, false, false);
520}
henrik.lundin@webrtc.org845862f2014-03-06 07:19:28 +0000521
Shao Changbine62202f2015-04-21 20:24:50 +0800522TEST_F(RampUpTest, UpDownUpThreeStreams) {
523 RunRampUpDownUpTest(3, false, false);
524}
henrik.lundin@webrtc.org998cb8f2014-03-06 09:12:00 +0000525
Shao Changbine62202f2015-04-21 20:24:50 +0800526TEST_F(RampUpTest, UpDownUpOneStreamRtx) {
527 RunRampUpDownUpTest(1, true, false);
528}
henrik.lundin@webrtc.org998cb8f2014-03-06 09:12:00 +0000529
Shao Changbine62202f2015-04-21 20:24:50 +0800530TEST_F(RampUpTest, UpDownUpThreeStreamsRtx) {
531 RunRampUpDownUpTest(3, true, false);
532}
533
534TEST_F(RampUpTest, UpDownUpOneStreamByRedRtx) {
535 RunRampUpDownUpTest(1, true, true);
536}
537
538TEST_F(RampUpTest, UpDownUpThreeStreamsByRedRtx) {
539 RunRampUpDownUpTest(3, true, true);
540}
henrik.lundin@webrtc.org845862f2014-03-06 07:19:28 +0000541
pbos@webrtc.org85bd53e2014-12-10 10:36:20 +0000542TEST_F(RampUpTest, AbsSendTimeSingleStream) {
Shao Changbine62202f2015-04-21 20:24:50 +0800543 RunRampUpTest(1, 0, RtpExtension::kAbsSendTime, false, false);
pbos@webrtc.org85bd53e2014-12-10 10:36:20 +0000544}
545
546TEST_F(RampUpTest, AbsSendTimeSimulcast) {
Shao Changbine62202f2015-04-21 20:24:50 +0800547 RunRampUpTest(3, 0, RtpExtension::kAbsSendTime, false, false);
pbos@webrtc.org85bd53e2014-12-10 10:36:20 +0000548}
549
550TEST_F(RampUpTest, AbsSendTimeSimulcastWithRtx) {
Shao Changbine62202f2015-04-21 20:24:50 +0800551 RunRampUpTest(3, 0, RtpExtension::kAbsSendTime, true, false);
552}
553
554TEST_F(RampUpTest, AbsSendTimeSimulcastByRedWithRtx) {
555 RunRampUpTest(3, 0, RtpExtension::kAbsSendTime, true, true);
pbos@webrtc.org85bd53e2014-12-10 10:36:20 +0000556}
557
558TEST_F(RampUpTest, AbsSendTimeSingleStreamWithHighStartBitrate) {
Shao Changbine62202f2015-04-21 20:24:50 +0800559 RunRampUpTest(1, 0.9 * kSingleStreamTargetBps, RtpExtension::kAbsSendTime,
560 false, false);
pbos@webrtc.org85bd53e2014-12-10 10:36:20 +0000561}
pbos@webrtc.org744fbc72013-09-10 09:26:25 +0000562} // namespace webrtc